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 8 of 8

Thread: BlueJ question: "Error: illegal initializer for java.util.ArrayList<java.lang.String>"

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default BlueJ question: "Error: illegal initializer for java.util.ArrayList<java.lang.String>"

    I am trying to use BlueJ to debug my java code for my homework. I am trying to pass arraylist to one of the methods and part of code (relevant) is posted under. Code compiles fine but when I try to create an object instance and input the string arraylist it is not working. I guess I need to know how to input data (parametric) into blueJ prompts when using an arraylist.

    I wish I could attach the snapshots of the errors but this forum blocks them. I will try to attach them again anyway to see if that works somehow. I have tried to input in a few different ways but I always get one or the other error in BlueJ, sample of error messages as below:

    BlueJ error:

    a)
    "Error: illegal initializer for java.util.ArrayList<java.lang.String>"

    OR

    b)
    "Error: <identifier> Expected"


    Code Snippet:

    [highlight=java]
    import java.util.ArrayList;
    public class ArrayListMethods
    {
        ArrayList<String> list; //instance variable
     
        public ArrayListMethods(ArrayList<String> arrayList)
        {
             list = new ArrayList<String>();
        }
     
     
        public boolean isSorted()
        {
            boolean sorted = false;
     
            for (int i = 0; i < list.size()-1; i++)
            {
                 if (list.get(i).compareTo(list.get(i+1)) > 0)
                 {
                     sorted = true;
                 }
     
            }
            return sorted;
        }
    }
     
    [/highlight]
    Attached Images Attached Images


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: BlueJ question: "Error: illegal initializer for java.util.ArrayList<java.lang.String>"

    What do you mean by "it is not working" ... that tells us nothing useful.
    I do not use bluej, so no advice there other than try your favorite search engine.
    Always copy-paste the full text of the error message with your code and question.

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: BlueJ question: "Error: illegal initializer for java.util.ArrayList<java.lang.String>"

    Please see the attachments for explanation of the errors. If you do not know BlueJ, please do not attempt to answer questions.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: BlueJ question: "Error: illegal initializer for java.util.ArrayList<java.lang.String>"

    If this is a BlueJ question and not a question about Java programming it should be posted in the IDE section.
    Let me know and I'll move the thread to the IDE section.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: BlueJ question: "Error: illegal initializer for java.util.ArrayList<java.lang.String>"

    If you expect someone to read the errors, post the full text of the error messages on the forum and not as attachments.
    Do not be so quick to shun someone who does not use the IDE of your choice, you never know what assistance they may provide.

  6. #6
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: BlueJ question: "Error: illegal initializer for java.util.ArrayList<java.lang.String>"

    Puller,
    Can you please post your entire code? We wanted to know where exactly the error occured? Definitely I see there is no compile-time error or runtime exception in the code you posted. But certainly your logic to check if the list is sorted is 100% wrong. Just try the input "b", "a", "c", "e" and see what output you get. It will return true when it is supposed to return false. But thats a different issue though.
    The error you said is probably in some other code which you did not display.

    Syed.

  7. #7
    Junior Member
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: BlueJ question: "Error: illegal initializer for java.util.ArrayList<java.lang.String>"

    I am giving up...thanks for all the help.

  8. #8
    Junior Member
    Join Date
    Sep 2013
    Location
    Denmark
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: BlueJ question: "Error: illegal initializer for java.util.ArrayList<java.lang.String>"

    You can find the answer to the question here: java - How do I enter parameters for an ArrayList in BlueJ? - Stack Overflow

Similar Threads

  1. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  2. Replies: 1
    Last Post: April 7th, 2013, 03:40 PM
  3. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  4. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  5. Replies: 1
    Last Post: January 15th, 2010, 01:32 AM

Tags for this Thread