Solved

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

Posted on 2006-06-26
10
5,447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 14

Assisted Solution

by:StillUnAware
StillUnAware earned 100 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 100 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 200 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 100 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

733 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