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: ArrayList assistance

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default ArrayList assistance

    Goal is to get user input and sum together. I've tried it different ways. This is the one with the least amount of problems.

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.lang.Integer.parseInt

            ArrayList<Integer> leftCU = new ArrayList<>();
            {
                System.out.println("Please enter one at a time the number of CU's for each class that is left to complete. Enter Q when done.");
                leftCU.add(in.nextInt());
                while (in.hasNextInt()){
                    leftCU.add(in.nextInt());
                }
     
             int sum= 0;
            for(int i=0; i < leftCU.size(); i++){
                sum = sum + Integer.parseInt(leftCU.get(i));   
                            }
            }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: ArrayList assistance

    Can you post the source code line that has the error?
    If the problem is with the parseInt() method, is the arg passed to the method the correct data type?
    Read the API doc to see how to use the method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: ArrayList assistance

    The error I get is for the line:

    sum = sum + Integer.parseInt(leftCU.get(i));

    leftCu.get(i) is highlighted with an error of: incompatible types: Integer cannot be converted into a String.

    I don't see how I'm converting it into a string though. I want everything to stay an Integer.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: ArrayList assistance

    leftCu.get(i) is highlighted with an error of: incompatible types: Integer cannot be converted into a String.
    What data type is: leftCu.get(i)
    what data type does parseInt() take?
    You need to read the API doc for the parseInt() method to see what type of arg it takes.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    mrivera85 (July 4th, 2014)

Similar Threads

  1. In need of assistance!
    By Nexcit in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 11th, 2014, 05:24 AM
  2. Need some assistance please
    By JavaPhish in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 25th, 2012, 10:00 AM
  3. Ordering ArrayList by 3 conditions as you add to ArrayList
    By aussiemcgr in forum Collections and Generics
    Replies: 4
    Last Post: July 13th, 2010, 02:08 PM
  4. FileReader need assistance
    By tazjaime in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: November 8th, 2009, 01:12 AM
  5. [SOLVED] Extracting an How to ArrayList from an ArrayList and convert to int??
    By igniteflow in forum Collections and Generics
    Replies: 2
    Last Post: August 16th, 2009, 01:11 PM