*
The moose likes Beginning Java and the fly likes Simple Chat Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Simple Chat Problem" Watch "Simple Chat Problem" New topic
Author

Simple Chat Problem

Moe Kennedy
Greenhorn

Joined: Aug 29, 2011
Posts: 7
Hello
I'm trying to make a small chat programm. It should not be perfect. ;-)

Here is the code I have already, unfortunately it is not working.
This is the Server:


This is the client:


Would be nice if someone coud help me.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Let's start at the beginning: how can you tell it isn't working?
Moe Kennedy
Greenhorn

Joined: Aug 29, 2011
Posts: 7
Hi
Paul Clapham wrote:Let's start at the beginning: how can you tell it isn't working?


When I try to run one of these files, an error appears:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method main cannot be declared static; static methods can only be declared in a static or top level type

at server.SimpleChatServer$ClientHandler.main(SimpleChatServer.java:40)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11175
    
  16

You wrote 200ish lines of code before you tried compiling?

that's your problem right there. Never write more than 2-3 lines before you compile. If you do, you are dooming yourself to failure.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

That message says that your "public static void main" method shouldn't be inside that nested class. Move it out of there so that it's a method of SimpleChatServer.
Moe Kennedy
Greenhorn

Joined: Aug 29, 2011
Posts: 7
Paul Clapham wrote:That message says that your "public static void main" method shouldn't be inside that nested class. Move it out of there so that it's a method of SimpleChatServer.


Thank you :thumbup:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple Chat Problem
 
Similar Threads
Client disconnected from server after about 10 minutes of inactivity
Help with Chat software
Help with this "ready-bake code", implementing Runnable
Best way for login authentication
ServerSocket to SSL