|
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
K. Tsang wrote:From the code "connect" is null. To avoid this you can either do:
Or
Now the question is where and when you initialize "connect"?
Richard Tookey wrote:I don't have access to your main() methods but I can see no path through the client that actually calls runClient() which is needed to connect to the server so 'connect' is always null.
P.S. Don't throw debug information away by converting exceptions to simple System.err.println("some error message"). Print the stack trace!
E Armitage wrote:
Is not going to stop the null pointer. You must not do connect.getInputStream() if connect is null.
Charles Sexton wrote:
Richard Tookey wrote:I don't have access to your main() methods but I can see no path through the client that actually calls runClient() which is needed to connect to the server so 'connect' is always null.
P.S. Don't throw debug information away by converting exceptions to simple System.err.println("some error message"). Print the stack trace!
Hey Richard, I just did the System.out.println(); to pin point the methods. I will eventually take them out and use ex.printStackTrace();
Also the main method calls runClient(); through an object.
Richard Tookey wrote:
Charles Sexton wrote:
Richard Tookey wrote:I don't have access to your main() methods but I can see no path through the client that actually calls runClient() which is needed to connect to the server so 'connect' is always null.
P.S. Don't throw debug information away by converting exceptions to simple System.err.println("some error message"). Print the stack trace!
Hey Richard, I just did the System.out.println(); to pin point the methods. I will eventually take them out and use ex.printStackTrace();
You have it back to front! You need the stack trace while you are in your current state i.e. debugging! In this situation you get far more information out of a stack trace than you will ever get from a System.out !
Also the main method calls runClient(); through an object.
Which of course we can't verify that it is done correctly since you have not posted the main methods. The fact is 'connect' is most probably null so you have to verify that you have called runClient() on the correct object before the GUI is constructed. We can't do that since we don't have access to the code that is supposed to do it!
Richard Tookey wrote:For some reason that totally escapes me your client code creates 4 instances of class Client but only applies the runClient() on one of them so 3 of the clients will never have made a connection to the server! I suspect you should stand back and review your design because your client code looks to be creating too many instances of your client and, since it is single threaded, your server code can handle only one client at a time.
Your big-bang approach rarely works. You should start with a much more simple client-server program. The server should be able to handle multiple simultaneous connections and the client should be able to handle multiple request/response actions. Initially there should be no GUI. Until you have the simple system working and you fully understand the concepts you are probably wasting your time trying anything a complex as your current work.
In my view you should really spend a lot of time studying http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html and in particular the "Supporting Multiple Clients" section.
Charles Sexton wrote:
This is a past due school assignment in which I am trying to get help in
and I assume you are saying start over with something that just writes to the system?
Richard Tookey wrote:
Charles Sexton wrote:
This is a past due school assignment in which I am trying to get help in
As was said on day one of this thread, 'connect' is null and you need to address that problem and the only way I can see to address that is to address the fundamental design issue. Since you are already in extra time I can't see that I can help further without actually re-writing the code for you which would not really help you.
and I assume you are saying start over with something that just writes to the system?
In effect yes but your time constraints make that sound impossible.
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|