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

Head First Java Chapter 15 problem

 
Michael Hall
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using non static member variables inside a static method.

Replace

By
 
Vinayak patil
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Hall
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic