whats wrong with my code.
this is before change
import java.util.InputMismatchException;
import java.util.Scanner;
public class ItemTest {
public static void main(String[] args) {
Item [] item = new Item[100];
for(int a=0; a<item.length; a++){
item[a] = new Item();
}
mainMenu(item);
}
public static void mainMenu(Item[] item){
...
...
...}
I was going to change my array by using the java.util.ArrayList.
but i don know is where wrong about the code .
can any1 help me .
after change
import java.util.InputMismatchException;
import java.util.Scanner;
public class ItemTest {
public static void main(String[] args) {
java.util.ArrayList Item = new java.util.ArrayList();
// for(int a=0; a<item.length; a++){
// item[a] = new Item();
}
mainMenu(Item);
}
public static void mainMenu(Item){
..
..}
can tell me where is the error.thanks
Re: whats wrong with my code.
What error? Do you get a compiler error? An error I see is that there is not an ending } for the class
Please copy and paste here the full text of the error message.
Re: whats wrong with my code.
If you're asking how to add an item to an ArrayList, see the ArrayList API docs.
If your ArrayList is going to hold Items, it would be sensible to call it 'items'. If you call it 'Item', how will the compiler know when you mean the ArrayList and when you mean the Item class? Use the Java Naming Conventions (class names start with an uppercase letter, method and variable names start with a lowercase letter).
If you want to pass an ArrayList to the mainMenu method, you need to declare it as a parameter.
Re: whats wrong with my code.