The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: get element of ArrayList.

You were correct with your call to info.get(3) to get the element in index 3, but you were wrong to compare it with 1. I assume MusicRecording is not a number. What variable in MusicRecording are you wanting to look at?

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: get element of ArrayList.

Ok, getOwned() returns a String, not an int, so you cannot compare it to 1 (and you should compare Strings with the .equals() method, not == ). Looking back up at your origional post, you can get the value the getOwned() method of the MusicRecording object in index 3 by saying:

Can you give examples of what values are you expecting your owned variable to be?

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: get element of ArrayList.

If it is only ever yes or no, then you should probably be using a boolean instead. A boolean is a simple-type whose only values can be true or false. Booleans are FAR easier to work with than Strings, since booleans are not objects, they are easier to set, and they are easier to use in logicial conditions (such as if statements). Here is a useful link: Java: Boolean

booleans can be set several ways. Such as simply saying:

boolean b =false;
b =true;
b =false;

They can even be set with logical operations. For example, if we had two ints (intA and intB) and we wanted boolean b to be set to true whenever intA is greater thanintB, we could say:

Or you can set them with methods that return true or false values. For example, if we had to Strings (strA and strB) and we wanted boolean b to be set to true whenever strA is the same text asstrB, we could say:

String strA ="Some Text";String strB ="Some Text";boolean b = strA.equals(strB);//sets b to true in this case, since strA and strB are the same

Last edited by aussiemcgr; May 11th, 2012 at 03:18 PM.

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Re: get element of ArrayList.

What line is 132? A null pointer means you have not initialized something.

NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.

Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/