aspose file tools*
The moose likes Beginning Java and the fly likes My Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "My Array" Watch "My Array" New topic
Author

My Array

Vianna Dublin
Greenhorn

Joined: Mar 07, 2010
Posts: 6
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

Joined: Jan 10, 2002
Posts: 61437
    
  67

You forgot to show us what the errors are.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't see an array anywhere at all, either. (Well, apart from the parameter to main.)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
And welcome to the Ranch
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

[ Jesper Young: Unnecessary quote of the whole original message deleted ]

where is the problem ???

Thanks,
Sherif
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Aug 16, 2005
Posts: 14274
    
  21

One problem that I see is that your main() method is not static. Change line 57 to this:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1691
    
  12



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:


When you do things right, people won't be sure you've done anything at all.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Remember method names (identifiers) ought not to start with capital letters.
Vianna Dublin
Greenhorn

Joined: Mar 07, 2010
Posts: 6
Sorry. I dont know how to generate the errors.
I'm just totally confused.

Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1691
    
  12

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

Joined: Mar 07, 2010
Posts: 6
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

Joined: Mar 17, 2005
Posts: 33
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

Joined: Mar 07, 2010
Posts: 6
So you mean like this? I'm still having a problem with the object though.



}
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 189
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

Joined: Mar 07, 2010
Posts: 6
I was using eclipse to program and as one of the suggested solution to the errors was to put in static.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: My Array