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: incompatible types

  1. #1
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default incompatible types

    Calculator.java:26: incompatible types
    found   : java.lang.String
    required: int
               switch (size) {
                       ^
    1 error
    Finished!
    Press any key to continue . . .

    that's my error. i understand it but i don't know what int i should put there.

    heres my code

    	public static void main(String[] args) {
          System.out.print("Enter your equation size and press Enter: ");
           BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
           String size = null;
           try {
             size = br.readLine();
           } catch (IOException e) {
             System.out.println("Error!");
             System.exit(1);
           }
    	   switch (size) {
    		   case 1:
    			oneStep();
    		   break;
     
    		   case 2:
    			twoStep();
    		   break;
    	   }
           System.out.println("Your equation size is: "+size);
    	}


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,298
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: incompatible types

    You haven't really given us any information to go from. What are you trying to do? What is "size" supposed to represent?

    Are you just trying to convert a String into a number? If so, check out the Integer API for useful functions.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: incompatible types

    some 1 will input the size of the equation they want to do. 1 step = 1 two step = 2 ect.

    if some 1 inputs one its supposed to preform the function oneStep();

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,298
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: incompatible types

    Okay, and did you check out the API for Integer?

    Hint: You're looking for the int value of a String, right?

    I'll even give you a link to the API: Java Platform SE 6
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. incompatible types Exception
    By world.java in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 17th, 2010, 12:33 PM
  2. Replies: 4
    Last Post: September 5th, 2010, 10:29 AM
  3. Incompatible Types
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2010, 09:52 AM
  4. Storing in different types of variables
    By giorgos in forum Collections and Generics
    Replies: 0
    Last Post: November 22nd, 2009, 01:02 PM
  5. Java chatting program implementing socket logic
    By sivakrishna.g in forum Java Networking
    Replies: 2
    Last Post: October 20th, 2009, 12:47 AM