[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-06-26
10
Medium Priority
?
5,471 Views
Last Modified: 2013-11-23
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
Comment
Question by:blue-genie
9 Comments
 
LVL 14

Assisted Solution

by:StillUnAware
StillUnAware earned 300 total points
ID: 16985227
Simply the java.util.StringTokenizer is not supprted by CLCD1.1

See this documentation:
http://jcp.org/aboutJava/communityprocess/final/jsr139/index.html
0
 
LVL 92

Assisted Solution

by:objects
objects earned 300 total points
ID: 16985292
0
 
LVL 14

Expert Comment

by:StillUnAware
ID: 16985305
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 39

Author Comment

by:blue-genie
ID: 16985423
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
 
LVL 39

Author Comment

by:blue-genie
ID: 16985436
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
 
LVL 14

Accepted Solution

by:
hoomanv earned 600 total points
ID: 16986352
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
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 300 total points
ID: 16989581
>> 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
 
LVL 39

Author Comment

by:blue-genie
ID: 16990362
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
 
LVL 39

Author Comment

by:blue-genie
ID: 17182179
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month18 days, 15 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question