• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException.

 
Mania Pawar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i having one problem in following code

error "Uncaught exception java/lang/NullPointerException."

///////////////////httpconn.java /////////////

import javax.microedition.lcdui.*;
import javax.microedition.io.*;

import java.io.*;
public class httpconn implements Runnable
{
private String url;
private InfoForm fmInfo;
private smsindya midlet;
protected writesms wrsms;

public httpconn(String url, InfoForm fmInfo1)
{
this.midlet = midlet;
this.url = url;
this.fmInfo = fmInfo1;
}

public void run()
{
parseNewsFeed();
}

public void start()
{
Thread thread = new Thread(this);
try
{
thread.start();
}
catch (Exception e)
{
fmInfo.setMessage("Fatal: Unable to start the SMSIndya.");
}
}

private void parseNewsFeed()
{

StreamConnection conn = null;
InputStream s = null;
StringBuffer b = new StringBuffer();
try
{

fmInfo.setMessage("trying to connect ...");
//error occur in this line
conn = (StreamConnection)Connector.open(url);

if (conn == null)
{
fmInfo.setMessage("no connection to \n" + url);
return;
}
else
{
fmInfo.setMessage("reading ...");
}

s = conn.openInputStream();
int ch;
while((ch = s.read()) != -1) {
b.append((char) ch);
}

if (b.toString()=="Blank Values")
{
fmInfo.setMessage(b.toString());
}
else
{
midlet.display.setCurrent(wrsms);
}
}
catch (Exception e)
{
fmInfo.setMessage("Error parsing XML!" + e.toString());
}
finally
{
try
{
if (conn != null)
{
conn.close();
}
if(s != null)
{
s.close();
}
}
catch (IOException ignored)
{
fmInfo.setMessage("IO exception" + ignored.toString());
}
}
}
}
//////////////////////////////////////////////

/*--------------------------------------------------
* InfoForm.java
*
* Extend Form component to show system/info messages
*-------------------------------------------------*/
import javax.microedition.lcdui.*;
public class InfoForm extends Form implements CommandListener
{
private Command cmBack;
private StringItem Message;
private smsindya midlet;
public InfoForm(smsindya midlet)
{

super("Information");

this.midlet = midlet;

cmBack = new Command("Back", Command.BACK, 2);
Message = new StringItem ("Please wait", "");

addCommand(cmBack);
append(Message);
setCommandListener(this);
}

public void commandAction(Command c, Displayable s)
{
if (c == cmBack)
{

midlet.display.setCurrent(midlet.fmsmsindya);
}


}

public void setMessage(String Message)
{
this.Message.setText(Message);
midlet.display.setCurrent(this);
}
}
/********************************************************************/

fmInfo.setMessage("trying to connect ...");
//error occur in this line

plz reply me i am waitting ur response.
thanks!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the entire stack trace so that we know which line to look at? Also when you post code, there is a CODE tag to use to keep your formating so that it is readable. The Code button below the Add Reply button does this for you.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic