Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incompatible Type error 1

Status
Not open for further replies.

rabix

Programmer
Apr 23, 2001
12
CH
hi,
i am trying to put some integer vales from the instance of a class to a List by

List sexList=new ArrayList();
sexList.add(Integer(PersonBean.getSex())); in a jsp page. but when i run the page i get an

error
Icompatible type for method. Can't convert double to java.lang.Object.
EndPensionList.add(BVGInsuredBean.getOldAgePension());
how can i avoid this error.
the getsex() method returns an integer.
thanx
Rabix
 
change "sexList.add(Integer(PersonBean.getSex()));"
to "sexList.add( new Integer(PersonBean.getSex()) );"

...
what is returned from "getOldAgePension" - a double? If so...
use this "EndPensionList.add( new Double(BVGInsuredBean.getOldAgePension()) );


...
Part of your problem is this... the add method of the List takes an Object and int and double variables are primitives not subclasses of the Object class so you need to wrap them with there Integer and Double counterparts.




I hope this helped! ;-)
- Casey Winans
 
hi casey,
thanx for the solutin. well i got a small doubt. how do u convert from Double to double or Integer to in?
thanx in advance.
rabix
 
double d = a_Double.doubleValue();
int i = a_Integer.intValue(); I hope this helped! ;-)
- Casey Winans
 
hi casey,
thanx for ur help. but i am still in trouble.



this is the way i have made the declarations

List AHVSalaryList=new ArrayList();
AHVSalaryList.add(new Double(PersonBean.getAHVSalary()));

and getAHVSalary() returnd double.


double AHVSalarySum = 0.0;


but when i do AHVSalarySum=AHVSalarySum+(Double)AHVSalaryList.get(i).doubleValue();
it gives the following error.



Incompatible type for +. Can't convert java.lang.Double to double.
AHVSalarySum=AHVSalarySum+(Double)AHVSalaryList.get(i).doubleValue();
^
Method doubleValue() not found in class java.lang.Object.
AHVSalarySum=AHVSalarySum+(Double)AHVSalaryList.get(i).doubleValue();


can u help me
thanx
rabix
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top