#1
  1. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469

    Java.lang.NullPointerException


    Guys, I'm working on an MIDP 2.0 app and I'm running into a little problem.
    Code:
    java.lang.NullPointerException
    	at ru.mobicomk.mfradio.util.Locale.loadProperties(+41)
    	at ru.mobicomk.mfradio.util.Locale.getString(+53)
    	at ru.mobicomk.mfradio.ui.PlayerUI.initCommands(+19)
    	at ru.mobicomk.mfradio.ui.PlayerUI.<init>(+139)
    	at ru.mobicomk.mfradio.controller.UIController.getPlayerUI(+16)
    	at ru.mobicomk.mfradio.controller.UIController.access$000(+4)
    	at ru.mobicomk.mfradio.controller.UIController$EventDispatcherThread.run(+247)
    I'm out of practice and my Java isn't what it used to be and I'm just not seeing it. Can anyone take a look at the attached project?
    Attached Files
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  2. #2
  3. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5054
    The line numbers from the zipped source don't match with what's being reported in that stack trace. Can you help narrow down line #41 in ru.mobicomk.mfradio.util.Locale? It'll be in the loadProperties() method.

    ~
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  4. #3
  5. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5054
    The first likely suspect is the "b = (byte) inStream.read();" line. If the earlier assignment to inStream by calling getResourceStream() doesn't find a resource by the name you provide ("/locale/" + locale + ".lng"), inStream will be null.

    ~
    Last edited by Yawmark; July 7th, 2010 at 01:50 PM.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  6. #4
  7. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469
    Originally Posted by Yawmark
    The line numbers from the zipped source don't match with what's being reported in that stack trace. Can you help narrow down line #41 in ru.mobicomk.mfradio.util.Locale? It'll be in the loadProperties() method.

    ~
    They don't match up for me either. That's half the problem I'm having I think. In any case, here's the entire function. Can't narrow down a line number.
    java Code:
        private static void loadProperties(Hashtable propertiesTable, String resourceName, boolean inlineTags) {
            try {
                propertiesTable.clear();
                InputStream inStream = propertiesTable.getClass().getResourceAsStream(resourceName);
                byte[] buf = new byte[1024];
                byte b;
                int bytesInLine = 0;
     
                String key = null;
                String lastKey = null;
                StringBuffer valueBuf = null;
     
                boolean EOF = false;
                while (!EOF) {
                    b = (byte) inStream.read();
                    switch (b) {
     
                        case -1:
                            EOF = true;
                        case '\n':
                            String str = decodeUTF8(buf, 0, bytesInLine);
                            int delimiterPos = str.indexOf('=');
     
                            if (delimiterPos != -1) {
                                if (lastKey != key && (valueBuf != null)) {
                                    putToHash(propertiesTable, inlineTags, key, valueBuf);
                                }
                                lastKey = key;
                                key = str.substring(0, delimiterPos);
                                valueBuf = new StringBuffer(str.substring(delimiterPos + 1));
                            } else {
                                valueBuf.append('\n' + str);
                            }
     
                            if (EOF) {
                                putToHash(propertiesTable, inlineTags, key, valueBuf);
                            }
     
                            bytesInLine = 0;
                            break;
     
                        default:
                            if (b != '\r') {
                                buf[bytesInLine++] = b;
                            }
                    }
                }
                inStream.close();
            } catch (EOFException ex) {
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            System.gc();
        }
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  8. #5
  9. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5054
    I'd have a good like at line #4 from your snippet. The most likely suspect is that inStream is null, which would result from not being able to find a resource by the name represented by resourceName. You can verify this by failing fast if (inStream == null) on the next line after the assignment.

    ~
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  10. #6
  11. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469
    Originally Posted by Yawmark
    The first likely suspect is the "b = (byte) inStream.read();" line. If the earlier assignment to inStream by calling getResourceStream() doesn't find a resource by the name you provide ("/locale/" + locale + ".lng"), inStream will be null.

    ~
    Hmm...maybe. The file exists though.

    When I run this in Wireless Toolkit with Trace Exceptions enabled, I'm getting some other unreported exceptions. Namely, one of them is an IO exception. But I have no way to narrow them down and I can't seem to convince Eclipse to load this project so I can try debugging it there.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  12. #7
  13. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    WDSMIA
    Posts
    10,135
    Rep Power
    5054
    The file exists though.
    Could be a funky classpath or classloading issue. I'd still try to fail fast after getting the stream. That could help narrow things down without needing the debugger.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}

IMN logo majestic logo threadwatch logo seochat tools logo