aspose file tools*
The moose likes Beginning Java and the fly likes Head First Java Chapter 15 problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java Chapter 15 problem" Watch "Head First Java Chapter 15 problem" New topic
Author

Head First Java Chapter 15 problem

Michael Hall
Greenhorn

Joined: Dec 17, 2005
Posts: 21
In chapter 15 of HFJ the following code is the first part of the SimpleChatClient code.


I am getting 10 errors all of the following type -

non-static variable incoming can not be referenced from a static context

concerning several variables and methods. Any suggestions? Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You are using non static member variables inside a static method.

Replace

By


[My Blog]
All roads lead to JavaRanch
Vinayak patil
Ranch Hand

Joined: Aug 30, 2005
Posts: 67
Hi,

Static variables and methods can be referenced without creating an object of the class.

For non- static methods and variables you must create an object.
Hence accessing non-static variables is not permitted inside static methods.

-Vinayak


"I can resist everything except temptation"
Michael Hall
Greenhorn

Joined: Dec 17, 2005
Posts: 21
I didn't even see the static there. Must have been getting tired. Thanks - compiles ok. I'll have another question soon about the chat client program in chapter 15.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Java Chapter 15 problem