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

Thread: incompatible types Exception

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default incompatible types Exception

    Hi,

    I am getting exception "incompatible types" while i am running the below code. Can you please let me know where i am doing wrong in the code?

    Thanks in advance

    Code:
    -------------------
    class emp_array
    {
     
    int id;
    	public emp_array (int id)
    	{
    		this.id = id;
    	}
     
    	public void showemp()
    	{
    		this.id= id;
    				System.out.println ("id  "+id);
     
    	}
     
     
    }
     
     
    class emp_arraydemo
    {
    	public static void main(String[] args) 
    	{
    		emp_array e[];
     
    		int n = args.length;
     
    		e = new emp_array[n];
     
    		for (int i=0; i<args.length;i++)
    		{
    			e[i]=Integer.parseInt(args[i]);
    		}
     
    		for (emp_array x:e)
    		{
    		x.showemp();
    		}
    	}
    }

    Error:
    ---------------------
    C:\Program Files\Java\jdk1.6.0_02\bin>javac emp_array_dynamically.java
    emp_array_dynamically.java:42: incompatible types
    found : int
    required: emp_array
    e[i]=Integer.parseInt(args[i]);
    ^
    1 error
    Last edited by copeg; November 17th, 2010 at 10:10 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: incompatible types Exception

    For future reference, please use the code tags.
    Here is your problem:
    e[i]=Integer.parseInt(args[i]);
    You are trying to assign an emp_array to an Integer/int. You should use the constructor of emp_array.

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: incompatible types Exception

    e[i] = new emp_array(Integer.parseInt(args[i]));

Similar Threads

  1. Replies: 4
    Last Post: September 5th, 2010, 10:29 AM
  2. Incompatible Types
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2010, 09:52 AM
  3. Exception during xml validation
    By vijeta in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 6th, 2010, 02:50 AM
  4. Storing in different types of variables
    By giorgos in forum Collections and Generics
    Replies: 0
    Last Post: November 22nd, 2009, 02: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