Welcome to the Java Programming Forums


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.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: whats wrong with my code.

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,408
    Thanks
    49
    Thanked 2,214 Times in 2,187 Posts

    Default 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.

  3. #3
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default 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.

  4. The Following User Says Thank You to dlorde For This Useful Post:

    jove (July 30th, 2011)

  5. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: whats wrong with my code.

    thanks , i get it

Similar Threads

  1. Whats wrong with my code!!
    By nitwit3 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 22nd, 2011, 11:45 AM
  2. Whats Wrong with this code?
    By whattheeff in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 9th, 2011, 09:59 PM
  3. Whats wrong with my code?
    By whattheeff in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 4th, 2011, 04:34 PM
  4. Whats wrong with my code?
    By mlan in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 27th, 2010, 12:42 PM
  5. i'm new to java. whats is wrong in this code?
    By igorek83 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 30th, 2009, 07:38 PM