Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5504
  • Last Modified:

J2ME - Midlet and using classes? java.lang.NoClassDefFoundError: java/util/StringTokenizer Error

Ok I'm using Eclipse and J2ME Wireless toolkit to develop midlets.
Now, when i create the file and i'm importing amongst others, the java.util.StringTokenizer.

however when i try to run my application using the emulator i get the error

java.lang.NoClassDefFoundError: java/util/StringTokenizer
      at Jargoneer.ParseVariableToJSP.getCourses(+179)
      at Jargoneer.ParseVariableToJSP.commandAction(+95)
      at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
      at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
      at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
      at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
      at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)

now i've looked all over google and this seems a rather common problem but i can't figure out what's up.
I'm a total newbie in the J2ME realms, but I'm thinking there's got to be something up with build paths or something, or somewhere it's not finding the right jar files or something.

Can anyone please help.
I'm also having the same problem with the kXML parser jar.

thanks.
blu.
0
blue-genie
Asked:
blue-genie
4 Solutions
 
StillUnAwareCommented:
Simply the java.util.StringTokenizer is not supprted by CLCD1.1

See this documentation:
http://jcp.org/aboutJava/communityprocess/final/jsr139/index.html
0
 
StillUnAwareCommented:
Also MIDP 2.0 does not include the java.util.StringTokenizer

The documentation:
http://jcp.org/aboutJava/communityprocess/final/jsr118/index.html


If You have the latest Sun Java Wireless Tollkit installed, and used the documentation provided, then You can notice that there is no documentation on java.util.StringTokenizer
So the only answer to this question is, that this utility is not supported for the Mobile Edition. It compiles as it uses the Standard Edition libraries, but it can't be executed on the emulator, which does not support all the SE functionality.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
blue-genieAuthor Commented:
ok, i get that not StringTokenizer doesnt' exist. however i still have the problem with external classes/jars.
i've now downloaded the net.comtor.j2me.util.StringVector java files, and i've added them and I can import them, but when i run the emulator, i still get the NoClassDefFoundError
0
 
blue-genieAuthor Commented:
what am i doing wrong?
i've taken all the class/java files and put them in a utils folder in my project in eclipse.
what else do i need to do?
please advise.
0
 
hoomanvCommented:
I've imported the j2se's StringTokenizer to j2me, here the code

public class StringTokenizer {
      public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000;
      public static final char MIN_HIGH_SURROGATE = '\uD800';
      public static final char MAX_LOW_SURROGATE  = '\uDFFF';
      public static final char MAX_HIGH_SURROGATE = '\uDBFF';
      public static final char MIN_LOW_SURROGATE  = '\uDC00';
      
      private int currentPosition;
      private int newPosition;
      private int maxPosition;
      private String str;
      private String delimiters;
      private boolean retDelims;
      private boolean delimsChanged;
      private int maxDelimCodePoint;
      private boolean hasSurrogates = false;
      private int[] delimiterCodePoints;

      private void setMaxDelimCodePoint() {
            if (delimiters == null) {
                  maxDelimCodePoint = 0;
                  return;
            }

            int m = 0;
            int c;
            int count = 0;
            for (int i = 0; i < delimiters.length(); i += charCount(c)) {
                  c = delimiters.charAt(i);
                  if (c >= MIN_HIGH_SURROGATE &&
                        c <= MAX_LOW_SURROGATE) {
                        c = codePointAt(delimiters, i);
                        hasSurrogates = true;
                  }
                  if (m < c)
                        m = c;
                  count++;
            }
            maxDelimCodePoint = m;

            if (hasSurrogates) {
                  delimiterCodePoints = new int[count];
                  for (int i = 0, j = 0; i < count; i++, j += charCount(c)) {
                        c = codePointAt(delimiters, j);
                        delimiterCodePoints[i] = c;
                  }
            }
      }

      public StringTokenizer(String str, String delim, boolean returnDelims) {
            currentPosition = 0;
            newPosition = -1;
            delimsChanged = false;
            this.str = str;
            maxPosition = str.length();
            delimiters = delim;
            retDelims = returnDelims;
            setMaxDelimCodePoint();
      }

      public StringTokenizer(String str, String delim) {
            this(str, delim, false);
      }

      public StringTokenizer(String str) {
            this(str, " \t\n\r\f", false);
      }

      private int skipDelimiters(int startPos) {
            if (delimiters == null)
                  throw new NullPointerException();

            int position = startPos;
            while (!retDelims && position < maxPosition) {
                  if (!hasSurrogates) {
                        char c = str.charAt(position);
                        if ((c > maxDelimCodePoint) || (delimiters.indexOf(c) < 0))
                              break;
                        position++;
                  } else {
                        int c = codePointAt(str, position);
                        if ((c > maxDelimCodePoint) || !isDelimiter(c)) {
                              break;
                        }
                        position += charCount(c);
                  }
            }
            return position;
      }

      private int scanToken(int startPos) {
            int position = startPos;
            while (position < maxPosition) {
                  if (!hasSurrogates) {
                        char c = str.charAt(position);
                        if ((c <= maxDelimCodePoint) && (delimiters.indexOf(c) >= 0))
                              break;
                        position++;
                  } else {
                        int c = codePointAt(str, position);
                        if ((c <= maxDelimCodePoint) && isDelimiter(c))
                              break;
                        position += charCount(c);
                  }
            }
            if (retDelims && (startPos == position)) {
                  if (!hasSurrogates) {
                        char c = str.charAt(position);
                        if ((c <= maxDelimCodePoint) && (delimiters.indexOf(c) >= 0))
                              position++;
                  } else {
                        int c = codePointAt(str, position);
                        if ((c <= maxDelimCodePoint) && isDelimiter(c))
                              position += charCount(c);
                  }
            }
            return position;
      }

      private boolean isDelimiter(int codePoint) {
            for (int i = 0; i < delimiterCodePoints.length; i++) {
                  if (delimiterCodePoints[i] == codePoint) {
                        return true;
                  }
            }
            return false;
      }

      public boolean hasMoreTokens() {
            newPosition = skipDelimiters(currentPosition);
            return (newPosition < maxPosition);
      }

      public String nextToken() {
            currentPosition = (newPosition >= 0 && !delimsChanged) ?
                                      newPosition : skipDelimiters(currentPosition);

            delimsChanged = false;
            newPosition = -1;

            if (currentPosition >= maxPosition)
                  return null; // throw new NoSuchElementException();
            int start = currentPosition;
            currentPosition = scanToken(currentPosition);
            return str.substring(start, currentPosition);
      }

      public String nextToken(String delim) {
            delimiters = delim;
            delimsChanged = true;
            setMaxDelimCodePoint();
            return nextToken();
      }

      public boolean hasMoreElements() {
            return hasMoreTokens();
      }

      public Object nextElement() {
            return nextToken();
      }

      public int countTokens() {
            int count = 0;
            int currpos = currentPosition;
            while (currpos < maxPosition) {
                  currpos = skipDelimiters(currpos);
                  if (currpos >= maxPosition)
                        break;
                  currpos = scanToken(currpos);
                  count++;
            }
            return count;
      }
      
      private int charCount(int codePoint) {
            return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT? 2 : 1;
      }
      
      private int codePointAt(String seq, int index) {
            char c1 = seq.charAt(index++);
            if (isHighSurrogate(c1)) {
                  if (index < seq.length()) {
                        char c2 = seq.charAt(index);
                        if (isLowSurrogate(c2)) {
                              return toCodePoint(c1, c2);
                        }
                  }
            }
            return c1;
      }
      
      private boolean isHighSurrogate(char ch) {
            return ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE;
      }
      
      private boolean isLowSurrogate(char ch) {
            return ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE;
      }
      
      private int toCodePoint(char high, char low) {
            return ((high - MIN_HIGH_SURROGATE) << 10)
                  + (low - MIN_LOW_SURROGATE) + MIN_SUPPLEMENTARY_CODE_POINT;
      }
}
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> but when i run the emulator

Might be because the emulator doesn't load the external JARs on its own - it might work in the actual scenario.
0
 
blue-genieAuthor Commented:
hoomany, I'll try that and see, mayankeagle - good point,i'll try that too.
thanks. will get back to you guys, wish me luck.
0
 
blue-genieAuthor Commented:
thanks for all ur help ppl, sorry i took so long, deadlines makes one forget.
i used a combination of things and some hacks, the application is still not working perfectly but i've managed to hack it to a working prototype stage which is what i needed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now