client-server help 'nullpointerexception'
hi there everyone
im new to this forum
i have this little problem with a client-server application that i have developed.
when a client tries to log into the sever (which runs on a different pc) using a username and password i get a 'nullpointerexception' error.
the thing is when i run both the client and server on the same pc it seems to work fine, and i cant seem to know what the problem is.
can someone help please.
if you need the code that im using and a screendump of the error that i get please let me know.
thanks in advance
hi there
thanks for the reply
the complete error that i get when i run the client from a different pc is shown below:
java.io.Filenotfoundexeption: admin_stock.ser (access is denied)
at java.io.FileoutputStream.open(native method)
at java.io.FileoutputStream.<init> (FileOutputStream.java:179)
at java.io.FileoutputStream.<init> (FileOutputStream.java:70)
at ServerWatchList.saveWatchList(ServerWatchList.java: 257)
at ServerWatchList.sendWatchList(ServerWatchList.java: 237)
at ServerWatchList.loadWatchList(ServerWatchList.java: 251)
at ServerWatchList.<init>(ServerWatchlist.java: 46)
at Server.run(Server.java: 82)
at java.lang.Thread.run(Thread.java: 595)
java.io.Filenotfoundexeption: admin_stock.ser (access is denied)
at java.io.FileoutputStream.open(native method)
at java.io.FileoutputStream.<init> (FileOutputStream.java:179)
at java.io.FileoutputStream.<init> (FileOutputStream.java:70)
at ServerWatchList.saveWatchList(ServerWatchList.java: 257)
at ServerWatchList.updateWatchList(ServerWatchList.java: 226)
at ServerWatchList.sendStockList(ServerWatchList.java: 206)
at ServerWatchList.<init>(ServerWatchlist.java: 46)
at Server.updateUsers(Server.java: 114)
at Server.run(Server.java: 84)
at java.lang.Thread.run(Thread.java: 595)
nullpointerexception
-
<<< the code that the error is refering to is below:>>>
for the ServerWatchList class
--
void sendStockList(Vector v) {
synchronized (out) {
out.println("__sol");
for (int i = 0; i < v.size(); i++)
out.println(v.elementAt(i));
out.println("__eol");
}
updateWatchlist(v);
}
void updateWatchlist(Vector v)
{
if(watchlist.isEmpty())
return;
for(int i=0;i<v.size();i++)
{
String stock = (v.elementAt(i)).toString();
for(int j=0;j<watchlist.size();j++)
{
String watchStock = (String)watchlist.elementAt(j);
if(stock.substring(0,stock.indexOf(" -")).equals(watchStock.substring(0,watchStock.indexOf(" -"))))
{
watchlist.remove(j);
watchlist.add(v.elementAt(i).toString());
}
}
}
saveWatchList();
}
void sendWatchlist()
{
synchronized (out) {
out.println("__sow");
for (int i = 0; i >< watchlist.size(); i++)
out.println(watchlist.elementAt(i));
out.println("__eow");
}
saveWatchList();
}
void loadWatchList()
{
FileInputStream fis;
try {
fis = new FileInputStream(name+"_stock.ser");
ObjectInputStream ois = new ObjectInputStream(fis);
watchlist = (Vector)ois.readObject();
} catch (Exception e) {
// TODO Auto-generated catch block
watchlist = new Vector<String>();
}
sendWatchlist();
}
void saveWatchList()
{
try {
FileOutputStream fos = new FileOutputStream(name+"_stock.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(watchlist);
oos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
-
for the Server class
public void updateusers()
{
for(int i=0;i<clients.size();i++)
{
((ServerWatchList)clients.elementAt(i)).sendStockList(Stock);
}
}
public void run()
{
while(true)
{
try
{
Socket client=serversocket.accept();
DataInputStream in=new DataInputStream(new BufferedInputStream(client.getInputStream()));
String name=in.readLine();
String passwd=in.readLine();
String authe=in.readLine();
if(auth(name,passwd,authe))
{
while(name.length()==0)
name=in.readLine();
ServerWatchList m=new ServerWatchList(in,new BufferedOutputStream(client.getOutputStream()),name,this);
clients.addElement(m);
updateusers();
}
else{
PrintWriter out = out = new PrintWriter(new BufferedOutputStream(client.getOutputStream()), true);
synchronized(out){
out.println("__nop");
}
}
}
catch (IOException e)
{
System.err.println(e.toString());
}
}
}
now i know its a lot of code but im not sure what im doing wrong
like i said before it works fine when the client logs in from the same pc as where the server is running.
if the code does not make any sense to you i can send you all of the classes and you can run them.
thanks again for your time>