Tuesday, 15 July 2014

java - Why do I get a ClassCastException and how do I fix it? -


Why do I get Class Cast Extension and how do I fix it? The code I got is the following exception message:

Exceptions to the thread "main" java.lang.ClassCastException :

  java.lang String can not be inserted into Java   

Here is my code:

   

Code> Import java.util *; Public class highscore {public static zero principal (string agre []) {array list & lieutenant; String & gt; Name = new ArrayList (); ArrayList & LT; Integer & gt; Score = new arrivate (); Start (name, score); Sort (name, score); Display (name, score); } Public Static Zero Start (ArrayList Name, ArrayList Score) {Scanners = New Scanner (System.in); Enter a name for {System.out.println ("Score #" + (i + 1 + + ":") for (Int i = 0; I ++); Names.add ( In.next ()); System.out.println ("Enter score for score #" + (i + 1) + ":"); Scores.add (in.next ());}} ( Constants = i; 0; i

The problem is that you score in the Reading String , and trying to put the score in an ArrayList of integer .

You will either need to read the score in the form of an integer, or parse the score in round.

See the API link below



No comments:

Post a Comment