×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    28

    java lang nullpointerexception

    Hi,

    I have two identical audio recording applications that match word by word. However, when i install the first one it runs correctly on my device(Nokia 3500c) whereas the second one gives me the error "java lang nullpointerexception".......

    It is pretty confusing and on top of that my debugger isnt working so i am unable to step thru each line to find out the issue. I am pasting both my codes below.

    Will someone please tell me why i am getting this error?


    Code Snippet1: Works Correctly

    public void startApp() {
    if (midletPaused) {
    resumeMIDlet ();
    } else {
    initialize ();
    startMIDlet ();
    try {
    //getAppProperty()
    Form frm=new Form("Recording");
    // Create a DataSource that captures live audio.
    Player p = Manager.createPlayer("capture://audio");
    p.realize();
    // Get the RecordControl, set the record location, and
    // start the Player and record for 5 seconds.
    RecordControl rc = (RecordControl)p.getControl("RecordControl");
    rc.setRecordLocation("file:///C:/predefgallery/predeftones/Audio.amr");
    // ByteArrayOutputStream output=new ByteArrayOutputStream();
    // rc.setRecordStream(output);
    rc.startRecord();
    p.start();
    frm.append("Recording Started");
    Display.getDisplay(this).setCurrent(frm);
    Thread.currentThread().sleep(5000);
    p.stop();
    rc.stopRecord();
    rc.commit();
    frm.append("Recording Stopped");
    }
    //catch (InterruptedException e) { }

    catch(Exception ex)
    {
    Form frm1=new Form("Error");
    frm1.append(ex.getMessage());
    Display.getDisplay(this).setCurrent(frm1);

    }



    Code Snippet2: (Gives me the Null Pointer Exception)

    public void startApp() {
    if (midletPaused) {
    resumeMIDlet ();
    } else {
    initialize ();
    startMIDlet ();
    try {
    //getAppProperty()
    Form frm=new Form("Recording");
    // Create a DataSource that captures live audio.
    Player p = Manager.createPlayer("capture://audio");
    p.realize();
    // Get the RecordControl, set the record location, and
    // start the Player and record for 5 seconds.
    RecordControl rc = (RecordControl)p.getControl("RecordControl");
    rc.setRecordLocation("file:///C:/predefgallery/predeftones/Audio.amr");
    // ByteArrayOutputStream output=new ByteArrayOutputStream();
    // rc.setRecordStream(output);
    rc.startRecord();
    p.start();
    frm.append("Recording Started");
    Display.getDisplay(this).setCurrent(frm);
    Thread.currentThread().sleep(5000);
    p.stop();
    rc.stopRecord();
    rc.commit();
    frm.append("Recording Stopped");
    }
    //catch (InterruptedException e) { }

    catch(Exception ex)
    {
    Form frm1=new Form("Error");
    frm1.append(ex.getMessage());
    Display.getDisplay(this).setCurrent(frm1);

    }
    }
    midletPaused = false;
    }


    One more thing....if i run the buggy application b4 the correct one then later when i try to run the correct application then that too gives me the same error......

    Can someone please help me here?

    Thanks in advance!

    Saket

  2. #2
    Super Contributor
    Join Date
    Jan 2007
    Location
    Bhubaneswar, India
    Posts
    1,189

    Re: java lang nullpointerexception

    check this wiki, may be you get some help.
    http://wiki.forum.nokia.com/index.ph...interException
    -------------------------------------
    Thanks & Regards
    Ram
    Symbian OS 9.2/9.3,S60 3rd FP1/FP2,Carbide.c++v2.0

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    28

    Re: java lang nullpointerexception

    Thanks Ram,

    But the link only gives one of the instance in which the Null Pointer Exception occurs.


    Anyways, one more observation................

    The exception occurs when i start the recording and start the player.

    Regards,
    Saket

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    28

    Re: java lang nullpointerexception

    Okay,

    I seem to have one possible explanation for this issue....

    Initially both the applications would record the file and save it in the Phone Memory. Maybe due to size constraints, once the first app saves its recorded file the 2nd app has no space to save its file and hence the error.

    Now when i save the recorded files to the external memory, then both the apps are working.

    I am not sure if this is it,or theres more here. I am still looking for some solid evidence.

    Regards,
    Saket

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    28

    Re: java lang nullpointerexception

    When i change recordControl.SetRecordLocation("path") to recordControl.SetRecordStream(OutputStream) i get the Null Exception.......

    Does anyone know why this happens? Could this also have something to do with the availabel size for the OutputStream?
    Also is there anyway to fix this?

    Thanks,
    Saket
    Last edited by j2meSak; 2009-11-18 at 12:47. Reason: Minor Changes

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    28

    Re: java lang nullpointerexception

    Okay so now i have narrowed my search to this.....

    Below is a small snippet of the code:

    p = Manager.createPlayer("capture://audio");
    p.realize();
    // Get the RecordControl, set the record location, and
    // start the Player and record for 5 seconds.
    rc = (RecordControl)p.getControl("RecordControl");
    //rc.setRecordLocation("file:///E:/Audio2.amr");
    output=new ByteArrayOutputStream(500);
    rc.setRecordStream(output);
    p.start();
    rc.StartRecord();

    Here if i only start the player or the recordcontrol.StartRecord there is no error.
    But when i start both as in the above case then only i get the NullPointerException error.

    Ofcourse i need to have both of them started so that the player also starts and also it records as well.....


    Finally, one more thing. Despite coding within the try catch block, the error is uncaught.

    Can anyone help please?

    Thanks,
    Saket

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

    Re: java lang nullpointerexception

    If the exception is not caught, then it isn't being thrown inside the try{} block.

    Graham.

  8. #8
    Registered User
    Join Date
    Nov 2009
    Posts
    28

    Re: java lang nullpointerexception

    Thanks Graham,

    I would like to debug the application, but the problem is that my debugger is not working.

    I put the breakpoints and when i debug the output window shows something like this:

    Waiting for debugger on port 2263
    KVM not ready. Trying again...
    nbdebug:
    KVM not ready. Trying again...
    KVM not ready. Trying again...
    KdpDebugTask connecting to debugger 1 ..
    KVM not ready. Trying again...
    KVM not ready. Trying again...
    Connection received.
    KdpDebugTask connecting to debugger 2 ..

    And i my application just does not load on the emulator. I tried looking online for some solution to this issue as well but no luck.


    But like i said before, why is it that when i type either Player.Start() or RecordControl.StartRecod() the program does not throw the NullPointer Exception?

    Its only when i include both these statements that the uncaught Null Pointer exception is thrown.......


    I think it has something to do with threads. Maybe the record control is getting defined on a seperate thread than the player. So while the record control is active i am unable to get access to the player and vice versa.

    If this is so then how do i solve this problem?

    Thanks for your comments,
    Saket
    Last edited by j2meSak; 2009-11-19 at 06:04. Reason: editing

Similar Threads

  1. -- Java development for S80 with Eclipse --
    By Kalypso in forum Mobile Java Tools & SDKs
    Replies: 3
    Last Post: 2011-03-17, 10:35
  2. GUI Libraries for Java ME
    By erik.hellman in forum Mobile Java Media (Graphics & Sounds)
    Replies: 5
    Last Post: 2008-04-11, 11:56
  3. Why is Java the Language of Choice of Most Mobile Game Developers and Not C++?
    By lightninglord2000 in forum General Development Questions
    Replies: 3
    Last Post: 2008-02-19, 18:00
  4. J2ME MIDlet is limited, why not Java applications on mobile?
    By chen_lin99 in forum Mobile Java General
    Replies: 11
    Last Post: 2007-12-29, 01:15
  5. j2ME, java enabled, and the 3410
    By davidkangaroo in forum Mobile Java General
    Replies: 2
    Last Post: 2002-07-05, 22:30

Posting Permissions

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