Results 1 to 3 of 3
Thread: Object to Int
- 10-22-2009, 08:00 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 11
- Rep Power
- 0
Object to Int
Hey guys,
I have a little problem with one of my program. I have a server/client scheme and I'm receiving a int value from my client into my server.
The thing is my server see it as an Object, and I need to change it back to an Int because later on my client I have a function which permit to lower the int number on my server. Don't really know if my explanation is very clear, but anyway here is the part of the code (summarized) which cause me trouble:
It's strange because for a double value for example I have no problem at all:public String doLesson(){
int places = 0;
places = Integer.parseInt(receive()); // Solution not working i found on google
Lesson i = new
Lesson(lessonNo,description,places.intValue(),loca tion);
server.put(lessonNo, i);
return "Lesson added";
}
Any ideas ?public String doLesson(){
Double places = 0.00;
places = (Double) receive(); // If only it was this simple with int, just adding (Int) receive(); - but not working :(
Lesson i = new
Lesson(lessonNo,description,places.doubleValue(),l ocation);
server.put(lessonNo, i);
return "Lesson added";
}
Cheers,
Clement
- 10-22-2009, 08:05 PM #2
When you System.out.println(recieve()); what does it look like? Because the Integer.parseInt(...) is trying to parse that exact string; my guess is that it doesn't look like an integer.
My Hobby Project: LegacyClone
- 10-22-2009, 08:26 PM #3
Member
- Join Date
- Sep 2009
- Posts
- 11
- Rep Power
- 0
I found the solution, here is the updated code:System.out.print("Enter number of places\t");
String places = getString();
send(new Integer(places));
Sorry for the trouble :)public String doLesson(){
int places = 0;
places = (Integer) receive();
Lesson i = new
Lesson(lessonNo,description,places,location);
server.put(lessonNo, i);
return "Lesson added";
}
Similar Threads
-
Operator < cannot be applied to java.lang.Object, Object
By Albert in forum Advanced JavaReplies: 2Last Post: 11-26-2010, 02:12 AM -
how to pass an arraylist from an object back to the parent object that it was created
By george_a in forum New To JavaReplies: 1Last Post: 03-04-2009, 06:14 PM -
Parsing a superclass object to subclass object dynamicly
By Andrefs in forum Advanced JavaReplies: 1Last Post: 07-22-2008, 04:27 PM -
[SOLVED] If a object equals another object, do they contain the same data?
By bobleny in forum New To JavaReplies: 1Last Post: 04-17-2008, 10:10 PM -
Creating object of Type Object class
By venkatv in forum New To JavaReplies: 3Last Post: 07-17-2007, 03:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks