Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

My Array

 
Vianna Dublin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've written up my code and ive tried adding in an array but i keep on getting errors. Can someone help please?
I want the fields to be in corresponding arrays.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64852
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You forgot to show us what the errors are.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see an array anywhere at all, either. (Well, apart from the parameter to main.)
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[ Jesper Young: Unnecessary quote of the whole original message deleted ]

where is the problem ???
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, you've not told us anything we can use to help you--are you getting an error? If so, what code is producing it? Do you just not know where/how to start? Please TellTheDetails, and remember that ItDoesntWorkIsUseless. Thanks!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One problem that I see is that your main() method is not static. Change line 57 to this:
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I would get rid of the empty Books() constructor. It makes no sense to have a book with no information, does it?

Then you could create one like so:


and output like:
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember method names (identifiers) ought not to start with capital letters.
 
Vianna Dublin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry. I dont know how to generate the errors.
I'm just totally confused.

 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using character arrays instead of strings? Oooohh.... I think I see....

Creating an object that consists of all character arrays is not the same as creating an array of objects.

I would still get rid of the empty constructor,

and then if you want to create an array of books, you can declare an ArrayList.

And this:

Doesn't do what you think it does.... I'm pretty sure.

Say in words what you're trying to do and maybe we can help you more.
 
Vianna Dublin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The no-arg constructor is supposed to be there. This is my appended code. The user should be able to input the amount of data to fill the fields how many times they want. They should also be able to view the data that they entered. Here is the appended code. Thanks

 
Baiju Scariah
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Book books[] = new Book; --> Is just an array reference, you haven't created object yet.

Thus before assigning any value you must say

for(int i....)
{
books[i] = new Book();

}


 
Vianna Dublin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you mean like this? I'm still having a problem with the object though.



}
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You did not define an Array of Book. Does every book have the same title, the same title, the same isbn? Why are those fields static? Do you understand what "static" means?
 
Vianna Dublin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was using eclipse to program and as one of the suggested solution to the errors was to put in static.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic