Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple Chat Problem

 
Moe Kennedy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21319
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's start at the beginning: how can you tell it isn't working?
 
Moe Kennedy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21319
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic