• Post Reply Bookmark Topic Watch Topic
  • New Topic

Syntax error, but not sure what i am doing wrong?  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this coding with an error showing on "p". that is in the first case in the switch statement.




how do i fix this? "p" is an array in another class.
 
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said p is in another class. You'll need an instance of that class and some way to access its members, either with a "getter" method (that's the preferred way) or by direct access (generally frowned upon).
 
Corey Hartman
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stevens Miller wrote:You said p is in another class. You'll need an instance of that class and some way to access its members, either with a "getter" method (that's the preferred way) or by direct access (generally frowned upon).


how would i go about doing that??? I understand the term, just am foggy... been doing his project for 6 hours straight now.
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, in which class is it? "Printer" or "Database"? Or some other class?

Note that accessing other classes purely via static methods (as the code does now) is not good object oriented design. you should consider instantiating objects in the "Main" class, and then calling methods on those objects.
 
Corey Hartman
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Well, in which class is it? "Printer" or "Database"? Or some other class?

Note that accessing other classes purely via static methods (as the code does now) is not good object oriented design. You should consider instantiating objects in the "Main" class, and then calling methods on those objects.



p is in database
 
Corey Hartman
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have tried moving it and no luck
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What, specifically, have you tried? If you make "p" public and static, then "Main" should have no problem accessing it via "Database.p". But as I said, that would not be a good design.
 
Greenhorn
Posts: 25
Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your Database and Person classes. I see you declared an ArrayList of Person in your main method. That should be in your Database class, but I don't know what you have in that class.

I also suspect that your "p" variable is supposed to be a Person object. You don't have it declared in the main method.

Never mind about posting your Database and Person classes. I see you did that in another thread.
 
Brian Schuetz
Greenhorn
Posts: 25
Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of declaring an ArrayList in main, you should be declaring a Database object.
In the other thread you had a method "handleAddPerson" that's not in this listing. That was almost where you want to be. You just didn't add the Person object to the Database object. In this thread you don't have that method, but you're trying to add "p" to the database but it isn't declared as a Person object, nor do you get any data for it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!