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

Reply With Quote



