client-server help 'nullpointerexceptionerror'


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: client-server help 'nullpointerexceptionerror'

  1. #1
    Join Date
    May 2006
    Posts
    3

    client-server help 'nullpointerexceptionerror'

    hi there.

    im new to this forum.
    i just have a little problem with this new client-server application that i created.
    the problem that i have is when the client tries to log into the server using a username and password i get a 'nullpointerexception' error and it wont let the client log in.

    when i use the client and server from the same machine it does let me in though.

    anyone has any ideas where i am going wrong, please let me know

    if you need to see the code and a screendump of the error that i get please let me know

    thanks in advance

  2. #2
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    post the stacktrace and the lines involved in the stack trace.

  3. #3
    Join Date
    May 2006
    Posts
    3

    code

    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

  4. #4
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    well, the stacktrace says that your problem is a file, that could not be found / written:

    java.io.Filenotfoundexeption: admin_stock.ser (access is denied)
    access denied points out, that you try to write (FileoutputStream.open(native method)) to the file called "admin_stock.ser", but you or your programm has not enough rights. (starting at the at ServerWatchList.saveWatchList(ServerWatchList.java : 257)).
    this shurely can lead to a following nullpointer exception.
    can that be right, that on the other machines, you run the client on, you don't have enough rights to create that file?

  5. #5
    Join Date
    May 2006
    Posts
    3

    reply

    well let me explain what the application does.

    the admin_stock file is saved in the Server folder and when admin tries to log in it needs to access that file to display the stock that are available.

    i have included a copy of the application and if you dont mind you can run it and see for yourself and maybe you can find what the problem is.
    there are three folders in the application, you first need to open the server folder and run the server.bat file and then open the admin or client folder and run the admin.bat or client.bat files. both folders do different things to the server.

    i also have included a screendump of the error that i get when i run the application in two different pc's.

    and thanks, i really appreciate what you're doin
    Attached Files Attached Files
    Last edited by tonymontana; 05-04-2006 at 05:52 PM.

  6. #6
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    the screenshot makes it clear: you have a problem accessing the file. perhaps the file is writeprotected? or it was created using another user than the one you are using now.

Similar Threads

  1. URGENT: FTP Client / Server using RMI
    By lwinn213 in forum Java
    Replies: 2
    Last Post: 10-23-2008, 01:14 PM
  2. Client server Question......Plz help
    By rohan076 in forum Java
    Replies: 1
    Last Post: 03-30-2006, 03:11 AM
  3. Client server communication with Winsock
    By Calderara Serge in forum Enterprise
    Replies: 1
    Last Post: 07-24-2002, 12:40 AM
  4. SQL Server installation on client machine
    By Vinny in forum Database
    Replies: 1
    Last Post: 01-31-2002, 04:59 PM
  5. Microsoft Sql Server 2000 Client DLL
    By Ramdas in forum Database
    Replies: 0
    Last Post: 05-16-2001, 02:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center