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:
-------------------
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
Re: incompatible types Exception
For future reference, please use the code tags.
Here is your problem:
Code :
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.
Re: incompatible types Exception
e[i] = new emp_array(Integer.parseInt(args[i]));