Greeting,
I'm currently programming a client-server connection with single socket...I use Linux C programming for server side, and J2me for client side, and here's the problem...
The login function run successfully for the server side, when It's a null exception for the client. The error is as follow:
java.lang.NullPointerException
at java.io.InputStream.read(InputStream.java:89)
at conn.Connectors.command(Connectors.java:62)
at mid.Midlet.commandAction(Midlet.java:136)
....
as for the code:
public class Connectors implements Runnable{
public SocketConnection con;
public InputStream is;
public OutputStream os;
public boolean exit = false, choosing = false;
public Midlet mid;
public String buff;
public byte buffs[];
public Connectors(Midlet mid){
this.mid = mid;
}
public void run() {
choosing = true;
try
{
con = (SocketConnection) Connector.open("socket://"+mid.cf.getAddr()+":8999");
os = con.openOutputStream();
os.write("alow".getBytes());
is = con.openInputStream();
}
catch (IOException ex) {
choosing = false;
exit = true;
ex.printStackTrace();
}
choosing = false;
while (!exit)
{
}
try{
os.write("exit".getBytes());
is.close();
os.close();
con.close();
}
catch (Exception e)
{}
}
public void stopNow()
{
exit = true;
}
public int command(String cmd,String args1,String args2)
{
try {
if (cmd.equals("login"))
{
os.write("login\n".getBytes());
Thread.sleep(10);
os.write((args1+ " " + args2).getBytes());
is.read(buffs); // here is LINE NO 62
buff = buffs.toString();
System.out.println(buff);
if(buff.equals("acc")){
return 1;
}
}
else
if (cmd.equals("reg"));
}
catch (Exception ex){
ex.printStackTrace();
}
return -1;
}
please help