×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    80

    SVG class, render() -> NullPointerException

    Hi,
    After using my little SVG based Splash class code OK for 7 months, I'm suddenly experiencing a NullPointerException in my Nokia 6210 Navigator causing the application to abort in the render() method. See code below. I use the NetBeans 6.7.1 IDE.

    Running in the emulator, see Output below, it reports the NullPointerException the first time the image is loaded but continues and succeeds next time. However, my SVG based mainMenu class works OK.

    HOWEVER, if I comment out the SVG Splash class in the StartApp(), the same NullPointerException problem will instead happen in the mainMenu class instead, and in the same way.

    So, it looks like this is a problem the first time an SVG image is created.
    See NetBeans 6.7.1 Output below.

    What can be the problem?
    /Per

    OUTPUT NetBeans 6.7.1
    *********************
    pre-init:
    pre-load-properties:
    exists.config.active:
    exists.netbeans.user:
    exists.user.properties.file:
    load-properties:
    exists.platform.active:
    exists.platform.configuration:
    exists.platform.profile:
    basic-init:
    cldc-pre-init:
    cldc-init:
    cdc-init:
    ricoh-pre-init:
    ricoh-init:
    semc-pre-init:
    semc-init:
    savaje-pre-init:
    savaje-init:
    sjmc-pre-init:
    sjmc-init:
    cdc-hi-pre-init:
    cdc-hi-init:
    nokiaS80-pre-init:
    nokiaS80-init:
    nsicom-pre-init:
    nsicom-init:
    post-init:
    init:
    conditional-clean-init:
    conditional-clean:
    deps-jar:
    pre-preprocess:
    do-preprocess:
    Pre-processing 0 file(s) into C:\Documents and Settings\admin\My Documents\NetBeansProjects\SoftAlarmR100\build\preprocessed directory.
    post-preprocess:
    preprocess:
    pre-compile:
    extract-libs:
    do-compile:
    post-compile:
    compile:
    pre-obfuscate:
    proguard-init:
    skip-obfuscation:
    proguard:
    post-obfuscate:
    obfuscate:
    lwuit-build:
    pre-preverify:
    do-preverify:
    Preverifying 18 file(s) into C:\Documents and Settings\admin\My Documents\NetBeansProjects\SoftAlarmR100\build\preverified directory.
    post-preverify:
    preverify:
    pre-jar:
    set-password-init:
    set-keystore-password:
    set-alias-password:
    set-password:
    create-jad:
    add-configuration:
    add-profile:
    do-extra-libs:
    nokiaS80-prepare-j9:
    nokiaS80-prepare-manifest:
    nokiaS80-prepare-manifest-no-icon:
    nokiaS80-create-manifest:
    jad-jsr211-properties.check:
    jad-jsr211-properties:
    semc-build-j9:
    do-jar:
    Building jar: C:\Documents and Settings\admin\My Documents\NetBeansProjects\SoftAlarmR100\dist\SoftAlarmR100.jar
    nsicom-create-manifest:
    do-jar-no-manifest:
    update-jad:
    Updating application descriptor: C:\Documents and Settings\admin\My Documents\NetBeansProjects\SoftAlarmR100\dist\SoftAlarmR100.jad
    Generated "C:\Documents and Settings\admin\My Documents\NetBeansProjects\SoftAlarmR100\dist\SoftAlarmR100.jar" is 347354 bytes.
    ricoh-init-dalp:
    ricoh-add-app-icon:
    ricoh-build-dalp-with-icon:
    ricoh-build-dalp-without-icon:
    ricoh-build-dalp:
    savaje-prepare-icon:
    savaje-build-jnlp:
    post-jar:
    jar:
    pre-run:
    netmon.check:
    open-netmon:
    cldc-run:
    Copying 1 file to C:\Documents and Settings\admin\My Documents\NetBeansProjects\SoftAlarmR100\dist\nbrun188544583382957287
    Copying 1 file to C:\Documents and Settings\admin\My Documents\NetBeansProjects\SoftAlarmR100\dist\nbrun188544583382957287
    Jad URL for OTA execution: http://localhost:8082/servlet/org.ne...tAlarmR100.jad
    Starting emulator in execution mode
    Running with storage root temp.SonyEricsson_JP8_240x320_Emu124
    Running with locale: Swedish_Sweden.1252
    ***************SVGSplash 1*************
    Using Pisces Renderer (native version)
    >>>>>>>>>>>> loadStarting : true
    >>>>>>>>>>>> loadComplete : true
    >>>>>>>>>>>> loadingFailed: false
    >>>>>>>>>>>> loadStarting : true
    >>>>>>>>>>>> loadComplete : true
    >>>>>>>>>>>> loadingFailed: false
    Uncaught exception java/lang/NullPointerException.
    ***************SVGSplash 2*************
    ***************SVGSplash 1*************
    ***************SVGSplash 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    Warning: To avoid potential deadlock, operations that may block, such as
    networking, should be performed in a different thread than the
    commandAction() handler.
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    Execution completed.
    43862590 bytecodes executed
    2398 thread switches
    1782 classes in the system (including system classes)
    0 dynamic objects allocated (0 bytes)
    0 garbage collections (0 bytes collected)
    ricoh-run:
    semc-icon-assembly:
    semc-ppro-emulator:
    semc-do-run:
    semc-run:
    savaje-run:
    sjmc-run:
    nokiaS80-run:
    nsicom-run:
    cdc-hi-run:
    profiler.check:
    open-profiler:
    run:
    BUILD SUCCESSFUL (total time: 35 seconds)
    -----------------------------------------------
    CODE:
    *****

    public SVGshowSplash (SoftAlarmR100 midlet) {
    this.midlet = midlet;

    setFullScreenMode(true);
    width = getWidth();
    height = getHeight();

    /*
    * Open the Input stream
    */
    try {
    svgImage = (SVGImage) SVGImage.createImage(getClass().getResourceAsStream("/SplashBetaKilsbergenVikern 240x320.svg"), null);
    }
    catch (Exception e) {
    alertUser = new Alert("Splash svgImage create error", e.toString() ,null,null);
    alertUser.setTimeout(5000);
    alertUser.setType(AlertType.ERROR);
    Display.getDisplay(midlet).setCurrent(alertUser);}

    scalableImage = svgImage;
    sg = ScalableGraphics.createInstance();
    sg.setRenderingQuality(ScalableGraphics.RENDERING_QUALITY_HIGH);

    }
    public void paint(Graphics g){

    // clear the display
    //g.setColor( 255, 255, 255 );

    sg.bindTarget(g);

    System.out.print(" ***************SVGSplash 1************* \n");
    sg.render(0,0, svgImage);
    System.out.print(" ***************SVGSplash 2************* \n");
    sg.releaseTarget();

    } //g



    public void hideNotify()
    {
    }

    public void showNotify()
    {
    }

    /********************************************
    * Handle screen size change
    ********************************************/
    protected void sizeChanged(int width,int height)
    {

    svgImage.setViewportWidth( width );

    svgImage.setViewportHeight( height );

    repaint();
    }

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: SVG class, render() -> NullPointerException

    Warning: To avoid potential deadlock, operations that may block, such as
    networking, should be performed in a different thread than the
    commandAction() handler.
    This should worry you. You really need to fix this problem.

    OK...

    Do you know (from exception details) exactly where the exception is being thrown? Is the code shown the same code you were running? I'm confused about how:

    ***************SVGSplash 2*************
    could print without "SVGSplash 1".

    Can you show us the code where you create an instance of this class, and put it on the screen?

    Graham.

  3. #3
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    80

    Re: SVG class, render() -> NullPointerException

    Hi Graham

    In the work of identifying where the NullPointer exception had its origin, I identified the render. So I put these printouts around it in the code. The code I supplied is the real code:

    System.out.print(" ***************SVGSplash 1************* \n");
    sg.render(0,0, svgImage);
    System.out.print(" ***************SVGSplash 2************* \n");

    If you look at the Output, the " ***************SVGSplash 1*************" is printed just before the redering output:
    ...
    Running with locale: Swedish_Sweden.1252
    ***************SVGSplash 1*************
    Using Pisces Renderer (native version)
    >>>>>>>>>>>> loadStarting : true
    >>>>>>>>>>>> loadComplete : true
    >>>>>>>>>>>> loadingFailed: false
    >>>>>>>>>>>> loadStarting : true
    >>>>>>>>>>>> loadComplete : true
    >>>>>>>>>>>> loadingFailed: false
    Uncaught exception java/lang/NullPointerException.
    ***************SVGSplash 2*************
    ...
    However, after running this a couple of times, the NullPointerException do appear anywhere between SVGSplash1 and SVGSplash2.

    -----------
    Thanks for the heads-up re. the Warning about deadlock. This might come from the MIDlet, where I yesterday implemented PushRegistry based AutoStart of my app and handling of incoming SMS. The AutoStart of my app works fine and the SMS do end up in the "notifyIncomingMessage(MessageConnection conn)". However, the Runnable I created to handle it have problems catching the incoming SMS. The variable "SMStext" is empty when catched correctly(?) in the Runnable SMSReader class. However if I skip the Runnable class and catch the SMS directly in the notifyIncomingMessage() method I get it. BTW I used the example in the JSR-120 Spec on page 23 as a base for this code.

    The only differences from the JSR-120 example are these:
    In the class SMSReader I added a refence to the MIDlet:
    "private SoftAlarmR100 midlet;"
    I also added a constructor to the class SMSReader that was missing in the example.
    // Constructor
    SMSReader(SoftAlarmR100 midlet){
    this.midlet = midlet;
    Was this incorrect?

    In startApp(), the first this is a call to getSMSmessage(). See below.

    public void getSMSmessage(){
    try {
    // Get our connection set up
    smsConn = (MessageConnection) Connector.open("sms://:50010");
    // Register a listener
    smsConn.setMessageListener(this);
    // Start the SMS reader thread
    done = false;
    SMSreader = new SMSReader(this);
    new Thread(SMSreader).start();
    }
    catch (java.io.IOException ioex) {
    alertUser = new Alert("01. SMS Connection I/O Error", ioex.toString() ,null,null);
    alertUser.setTimeout(10000);
    alertUser.setType(ERROR);
    Display.getDisplay(this).setCurrent(alertUser);
    }
    }

    public void notifyIncomingMessage(MessageConnection conn) {
    if(conn == null){
    alertUser = new Alert("5. notifyIncMess Error","conn = null" ,null,null);
    alertUser.setTimeout(5000);
    alertUser.setType(ERROR);
    Display.getDisplay(this).setCurrent(alertUser);
    }

    if ( conn == smsConn){
    // Activate the Runnable to read the SMS
    SMSreader.processMessage();
    }
    }

    // Runnable
    class SMSReader implements Runnable{
    private SoftAlarmR100 midlet;
    private int pendingSMS = 0;

    // Constructor
    SMSReader(SoftAlarmR100 midlet){
    this.midlet = midlet;
    }
    // the run method does the actual reading of incoming SMS's
    public void run() {
    while (!done) {
    synchronized(this) {
    if ( pendingSMS == 0) {
    try {
    // wait for a message to arrive
    wait();
    } catch (Exception exp) {
    // Handle interruption
    alertUser = new Alert("02. Runnable Wait Error", exp.toString() ,null,null);
    alertUser.setTimeout(10000);
    alertUser.setType(ERROR);
    Display.getDisplay(midlet).setCurrent(alertUser);
    }
    }
    pendingSMS--;
    }

    try {
    // Finally read and handle the SMS
    Message SMSmess = smsConn.receive();

    // Text Message
    //**************
    if (SMSmess instanceof TextMessage){
    TextMessage txtMsg = (TextMessage)SMSmess;
    SMStext = txtMsg.getPayloadText();
    alertUser = new Alert("03. Runnable SMS text: \n",SMStext ,null,null);
    alertUser.setTimeout(Alert.FOREVER);
    alertUser.setType(AlertType.CONFIRMATION);
    alertUser.addCommand(OKconf);
    alertUser.setCommandListener(midlet);
    Display.getDisplay(midlet).setCurrent(alertUser);
    // Now send the message to the SMS Command Scheduler

    // Binary Message
    //***************
    } if(SMSmess instanceof BinaryMessage){
    BinaryMessage binMsg = (BinaryMessage)SMSmess;
    binarySMSdata = binMsg.getPayloadData();
    // Now send the message to the SMS Command Scheduler


    }
    } catch (IOException ioex) {
    // Handle reading errors
    alertUser = new Alert("04. Runnable Message I/O Error", ioex.toString() ,null,null);
    alertUser.setTimeout(10000);
    alertUser.setType(AlertType.ERROR);
    Display.getDisplay(midlet).setCurrent(alertUser);
    }
    }
    }

    public synchronized void processMessage() {
    pendingSMS++;
    notify();
    }

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: SVG class, render() -> NullPointerException

    Quote Originally Posted by d-safety View Post
    If you look at the Output, the " ***************SVGSplash 1*************" is printed just before the redering output:
    Ah yes, sorry, I missed it.

    But... this means there's an uncaught exception, but you see the "SVGSplash 2" output anyway! Unless the exception is being thrown in a different thread...

    Does this only happen on the Sony Ericsson emulator? What about Nokia/Sun emulators? Can you enable extended exception details for the emulator? It would be useful to get a stack trace.

    Graham.

  5. #5
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    80

    Re: SVG class, render() -> NullPointerException

    The problem persist.
    Now with several exceptions. I cannot find a way to enable extended exception details for the emulator.
    I incread the verbosity level, however I no more info or stack trace for the NullPointerException. Where to make this happen?

    Same problem in Sun Java ME SDK 3.0.
    However, not in my SE W715(!).

    Also, I made a new SMS fetcher Runnable working. It start but hangs on the syncObj.
    See below.


    Latest run re. the multiple NullPointerExceptions:

    Starting emulator in execution mode
    Executing command line: "C:\SonyEricsson\JavaME_SDK_CLDC\WTK2\bin\emulator" -Xdevice:"SonyEricsson_JP8_240x320_Emu" -Xdescriptor:"C:\Documents and Settings\admin\My Documents\NetBeansProjects\SoftAlarmR100\dist\nbrun7956088102296344526\SoftAlarmR100.jad"
    Running with storage root temp.SonyEricsson_JP8_240x320_Emu137
    Running with locale: Swedish_Sweden.1252
    Uncaught exception java/lang/NullPointerException.
    ***************SVGSplash 1*************
    Using Pisces Renderer (native version)
    >>>>>>>>>>>> loadStarting : true
    >>>>>>>>>>>> loadComplete : true
    >>>>>>>>>>>> loadingFailed: false
    >>>>>>>>>>>> loadStarting : true
    >>>>>>>>>>>> loadComplete : true
    >>>>>>>>>>>> loadingFailed: false
    Uncaught exception java/lang/NullPointerException.
    ***************SVGSplash 2*************
    ***************SVGSplash 1*************
    ***************SVGSplash 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    Warning: To avoid potential deadlock, operations that may block, such as
    networking, should be performed in a different thread than the
    commandAction() handler.
    ***************SVGMenuCreate 1*************
    ***************SVGMenuCreate 2*************
    Execution completed.
    43474362 bytecodes executed
    4606 thread switches
    1782 classes in the system (including system classes)
    0 dynamic objects allocated (0 bytes)
    0 garbage collections (0 bytes collected)
    ricoh-run:
    .....
    run:
    BUILD SUCCESSFUL (total time: 56 seconds)

    New version of the Runnable for read new PushRegister SMS's.
    Introduced a syncObj.
    ============================================================
    public class SMSReader implements Runnable{
    private SoftAlarmR100 midlet;
    private int pendingSMS = 0;
    private final Object syncObj = null;

    // Constructor
    SMSReader(SoftAlarmR100 midlet){
    this.midlet = midlet;
    new Thread(this).start();
    }
    // the run method does the actual reading of incoming SMS's
    public void run() {
    while (!done) {
    synchronized(syncObj) { <-------- Hangs here
    if ( pendingSMS == 0) {
    try {
    Display.getDisplay(midlet).vibrate(300); <---- Debug. Doesn't reach this

    // wait for a message to arrive
    syncObj.wait();
    } catch (java.lang.InterruptedException exp) {
    // Handle interruption
    alertUser = new Alert("02. Runnable Wait Error", exp.toString() ,null,null);
    alertUser.setTimeout(10000);
    alertUser.setType(ERROR);
    Display.getDisplay(midlet).setCurrent(alertUser);
    }
    }
    pendingSMS--;
    }

    try {
    // Finally read and handle the SMS
    Message SMSmess = smsConn.receive();

    // Text Message
    //**************
    if (SMSmess instanceof TextMessage){
    TextMessage txtMsg = (TextMessage)SMSmess;
    SMStext = txtMsg.getPayloadText();

    Display.getDisplay(midlet).vibrate(300); <--- Debug. Doesn't reach this
    alertUser = new Alert("03. Runnable SMS text: \n",SMStext ,null,null);
    alertUser.setTimeout(Alert.FOREVER);
    alertUser.setType(AlertType.CONFIRMATION);
    alertUser.addCommand(OKconf);
    alertUser.setCommandListener(midlet);
    Display.getDisplay(midlet).setCurrent(alertUser);
    // Now send the message to the SMS Command Scheduler

    // Binary Message = encrypted SMS
    //********************************
    } if(SMSmess instanceof BinaryMessage){
    BinaryMessage binMsg = (BinaryMessage)SMSmess;
    binarySMSdata = binMsg.getPayloadData();
    // First decrypt the message.
    // CommsMgr.Decryption
    // Now send the message to the SMS Command Scheduler


    }
    } catch (IOException ioex) {
    // Handle reading errors
    alertUser = new Alert("04. Runnable Message I/O Error", ioex.toString() ,null,null);
    alertUser.setTimeout(10000);
    alertUser.setType(AlertType.ERROR);
    Display.getDisplay(midlet).setCurrent(alertUser);
    }
    }
    } // Run

    public synchronized void processMessage() {
    pendingSMS++;
    syncObj.notify();
    }

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: SVG class, render() -> NullPointerException

    You might be able to get more exception information if you run the emulator from the command line. Build a JAD and JAR first.

    Code:
    C:\SonyEricsson\JavaME_SDK_CLDC\WTK2\bin\emulator.exe -Xdevice:"SonyEricsson_JP8_240x320_Emu" -Xverbose:exceptions -Xdescriptor:application.jad
    Where "application.jad" is the name of your JAD file.

    I suggest you stop making changes to the code, until you know what to change. By making the code more and more complex, while it is broken in the first place, you are only making the original problem harder to find, and introducing more problems to confuse you.

    Graham.

  7. #7
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    80

    Re: SVG class, render() -> NullPointerException

    Thanks,
    Have tried your suggestion.
    The resulting output is roughly the same as before.

    Any other way I can get info, StackTrace or the origin of the two NullPointerExceptions?

    /Per

  8. #8
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: SVG class, render() -> NullPointerException

    I don't have the Sony Ericsson SDK. But you do, so take a look in the documentation for how to use the emulator.

  9. #9
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    80

    Re: SVG class, render() -> NullPointerException

    I just need a emulator that support Sensors. The Nokia S60 does not seem to support Sensors.
    I cannot make the Sun Java ME SDK 3.0 emulator to display the Emulator phone, even though it's listed among my Emulator Platforms, so I picked the SE SDK.

    So, now I really want to get the Java SDK 3.0 emulator rolling. I selected it, choosed the ClamShellCLCDCPhone1 and tried to Run the project. The Build phase is OK, but no emulator pops up. This has never been an issue before. What can stop the emulator from popping up?

    /Per

  10. #10
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: SVG class, render() -> NullPointerException

    If you are able to build a JAD and JAR, then again, you can try running the emulator from the command line. Take a look in the Java ME SDK 3.0 user guide, under Command Line Reference, Running the Emulator From the Command Line.

  11. #11
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    80

    Re: SVG class, render() -> NullPointerException

    For the future development, would you recommend me to use the Java ME SDK 3.0 emulator from within NetBeans, or should I move out to the stand alone Java ME SDK 3.0?

    /Per

  12. #12
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: SVG class, render() -> NullPointerException

    That depends how well you can work NetBeans. I never use NetBeans, so I can't advise you of the best way to use it. You might want to post SDK related questions in the SDK board where someone else might be better equipped to answer that.

  13. #13
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    80

    Re: SVG class, render() -> NullPointerException

    Case solved.
    Runnable in another class that suddenly had a problem with a parameter, after rining OK for 7 months.
    Strange.
    /Per

Similar Threads

  1. Replies: 7
    Last Post: 2007-06-08, 07:38
  2. Replies: 2
    Last Post: 2007-03-14, 17:15
  3. [q] howto? -> CInternetConnectionManager Class
    By Sami77 in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2003-07-18, 08:16
  4. Has Nokia broken 7650 J2ME in v4.39?
    By LongSteve in forum Mobile Java General
    Replies: 6
    Last Post: 2003-06-03, 17:05
  5. nokia 6210 class 1/2/2.0 fax transmission
    By help7 in forum Smart Messaging
    Replies: 0
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×