hi i am new in J2me & i am building a project using
java wireless toolkit..............in this project softalk mail server act as a server & outlook express is act as a client...
& whenever i try to launch my application after entering my username & password it shows a error "Network error in first Servletjava.lang.NullPointerException". what is this error ??
& how can i solve this.....
please help me ...... i need it urgently..
code is given below
"
import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
public class MCheques extends MIDlet
implements CommandListener
{
//declaration of variables
String schequeno;
private Display display;
public Form form1;
public Form form2;
private Command submit;
private Command exit;
public TextField username;
public TextField password;
private Command signin;
private TextField secretpass;
private TextField email;
private TextField payee;
private TextField chequeno;
private DateField dateofissue;
private DateField dateofcash;
private TextField amount;
public String s1;
public String s2;
public Alert alert;
public String Type;
public int Num;
private TextBox submission;
private StringItem bcb;
private StringItem stringitem;
private StringItem chequenostring;
//The constructor
public MCheques()
{
//Initialization of the commands
display = Display.getDisplay(this);
signin = new Command("Sign In", Command.SCREEN, 1);
submit = new Command("Submit", Command.SCREEN, 1);
exit = new Command("Exit", Command.EXIT, 1);
//initialazation of the variables
username = new TextField("UserName", "", 8, TextField.ANY);
password = new TextField("Password", "", 8, TextField.PASSWORD);
email = new TextField("Email of the Payee", "", 40, TextField.EMAILADDR);
secretpass = new TextField("Secret Key Password", "", 10, TextField.PASSWORD);
payee = new TextField("Name of Payee", "", 25, TextField.ANY);
chequenostring = new StringItem("Cheque No.","");
bcb = new StringItem("Your BCB Code:", "aaabbbccc");
dateofissue = new DateField("Issue Date", DateField.DATE);
dateofissue.setDate(new java.util.Date());
dateofcash = new DateField("Date of Cash",DateField.DATE);
amount= new TextField("Amount", "", 5, TextField.NUMERIC);
stringitem = new StringItem ("Welcome!!! "," ");
//initialization of the form
form1 = new Form("Login");
form2 = new Form("M-Cheque");
submission= new TextBox("Confirmation","Your cheque has been Sent Successfully",80,0);
submission.addCommand(exit);
form1.addCommand(signin);
form1.addCommand(exit);
form1.append(username);
form1.append(password);
form2.addCommand(exit);
form2.addCommand(submit);
form2.append(stringitem);
form2.append(chequenostring);
form2.append(email);
form2.append(payee);
form2.append(bcb);
form2.append(dateofcash);
form2.append(dateofissue);
form2.append(secretpass);
form2.append(amount);
form1.setCommandListener(this);
form2.setCommandListener(this);
submission.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(form1);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public class ApplicationException extends RuntimeException
{
ApplicationException(String s,int i)
{
String check;
//checking username
check="UserName";
if(check.equals(s))
{
alert=new Alert("ERROR","Invalid User Name",null,null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert,form1);
}
//checking password
check="Password";
if(check.equals(s))
{
alert=new Alert("ERROR","Invalid Password",null,null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert,form1);
}
//checking the secret password key
check="secretpass";
if(check.equals(s))
{
alert=new Alert("ERROR","Invalid SecretKey Password",null,null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert,form2);
}
//checking the email Id
check="email";
if(check.equals(s))
{
alert=new Alert("ERROR","Invalid Email Id.",null,null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert,form2);
}
//checking the payee name
check="Payee";
if(check.equals(s))
{
alert=new Alert("ERROR","You must enter a Valid Payee",null,null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert,form2);
}
//checking the date of cash
check="Dateofcash";
if(check.equals(s))
{
alert=new Alert("ERROR","Invalid Date of Cash.",null,null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert,form2);
}
//checking the Amount
check="Amount";
if(check.equals(s))
{
alert=new Alert("ERROR","Amount exceeds the max. limit-25000",null,null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert,form2);
}
}
}
public void commandAction(Command command, Displayable displayable) throws ApplicationException
{
if (command == signin)
{
HttpConnection http = null;
InputStream iStrm = null;
// Data is passed at the end of url for GET
String url = "
http://localhost:8080/examples/servlet/WebsiteDemo_CallServletGET6" + "?" +
"account=" + username.getString() + "&" +
"password=" + password.getString();
try
{
http = (HttpConnection) Connector.open(url);
// Client Request
// Send request method
http.setRequestMethod(HttpConnection.GET);
// Server Response
if (http.getResponseCode() == HttpConnection.HTTP_OK)
{
iStrm = http.openInputStream();
// Get body (data)
int length=8;
if (length > 0)
{
byte servletData[] = new byte[length];
iStrm.read(servletData);
// Update the string item on the display
String stemp= new String(servletData);
char[] ctemp = stemp.toCharArray();
int check=(int)ctemp[0] ;
if(check != '0')
{
alert=new Alert("Authentic","The User is authentic",null,null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert,form2);
stringitem.setText(username.getString());
chequenostring.setText(new String(servletData));
schequeno = new String(servletData);
}
else
{
alert=new Alert("ERROR","The user is not Authentic",null,null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert,form1);
}
}
else
form1.append("Unable to read data");
}
http.close();
iStrm.close();
}
catch (Exception e)
{
form1.append("Network error in First
Servlet"+e);
}
}
if (command == submit)
{
if (email.size() == 0)
{
Type="email";
Num=email.size();
throw new ApplicationException(Type,Num);
/* Complain about email being invalid... */
}
if (payee.size()==0)
{
Type="Payee";
Num=payee.size();
throw new ApplicationException(Type,Num);
/* Complain about size of the payeee feild
}
if (dateofcash.getDate().getTime()<dateofissue.getDate().getTime())
{
Type="Dateofcash";
Num=100;
throw new ApplicationException(Type,Num);
/* Complain about Date of Cash being empty... */
}
int amt=Integer.parseInt(amount.getString());
if (amt >25000)
{
Type="Amount";
Num=amt;
throw new ApplicationException(Type,Num);
/* Complain about amount exceeding the maximum value... */
}
String s1;
s1 = secretpass.getString();
String secretfill;;
secretfill="mcheques";
if (!s1.equals(secretfill))
{
Type="secretpass";
Num=secretpass.size();
throw new ApplicationException(Type,Num);
}
if (amt <= 25000)
{
HttpConnection http1 = null;
InputStream iStrm1 = null;
String doi_send = (dateofissue.getDate()).toString();
String doc_send = (dateofcash.getDate()).toString();
String doi_new="";
String doc_new="";
int leni = doi_send.length();
int lenc = doc_send.length();
char[] cdoi = doi_send.toCharArray();
char[] cdoc = doc_send.toCharArray();
int i=0;
while(i<leni)
{
if(cdoi[i]==' ')
{
i++;
}
else
{
doi_new = doi_new + cdoi[i];
i++;
}
}
i=0;
while(i><lenc)
{
if(cdoc[i]==' ')
{
i++;
}
else
{
doc_new = doc_new + cdoc[i];
i++;
}
}
// Data is passed at the end of url for GET
String url1 = "http://localhost:8080/examples/servlet/encryption_j2me11" + "?" +"user=" + username.getString() + "&" + "bcb=" + bcb.getText() + "&" + "email=" + email.getString() + "&" + "payee=" + payee.getString() + "&" + "doi=" + doi_new + "&" + "doc=" + doc_new
+ "&" + "amt=" + amount.getString() + "&" + "chequeno=" + schequeno;
try
{
http1 = (HttpConnection) Connector.open(url1);
http1.setRequestMethod(HttpConnection.GET);
form2.append(dateofissue.getDate().toString());
if (http1.getResponseCode() == HttpConnection.HTTP_OK)
{
iStrm1 = http1.openInputStream();
// Get body (data)
int length1 = url1.length();
if (length1 > 0)
{
byte serveData[] = new byte[length1];
iStrm1.read(serveData);
form2.append("You passed to the servlet: \n" + new String(serveData));
String stemp1= new String(serveData);
char[] ctemp1 = stemp1.toCharArray();
int check1=(int)ctemp1[0] ;
if(check1 == '1')
{
http1.close();
iStrm1.close();
display.setCurrent(submission);
}
}
}
else
form1.append("Unable to read data");
}
catch (Exception e)
{
form2.append("Network error in Second Servlet"+e);
}
}
}
else if (command == exit)
{
destroyApp(false);
notifyDestroyed();
}
}
}
"
>