class cast exception

Reply

Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

class cast exception

 
0
  #1
Dec 27th, 2007
hey guys
I'm trying to get hold of a StreamConnection

  1. try {
  2. StreamConnection conn = ( StreamConnection ) Connector.open ( url ) ;
  3.  
  4. } catch (Exception ex) {
  5. ex.printStackTrace();
  6. }

however when i do this i get the following error

java.lang.ClassCastException
According to my know of and google it should compile fine. I've used this in a J2EE project and it works correctly but not in a J2ME???
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,380
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: class cast exception

 
0
  #2
Dec 27th, 2007
J2ME (Micro/Mobile Edition) is a limited version of the J2SE (Standard Edition) and definately will not have anything that first available in the J2EE (Enterprise Edition).

See http://java.sun.com/javame/reference/apis.jsp#api and select the link for the appropriate version to see the API docs, and find out what is available.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: class cast exception

 
0
  #3
Dec 27th, 2007
I googled and quote the following websit whilst its implemented on J2EE its also available for J2ME

http://developers.sun.com/mobility/m...icles/network/
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 224
Reputation: bugmenot is an unknown quantity at this point 
Solved Threads: 31
bugmenot bugmenot is offline Offline
Posting Whiz in Training

Re: class cast exception

 
0
  #4
Dec 27th, 2007
the exception tells you exactly what's wrong; you can't cast it, because it's not that type

what makes you think that it is a StreamConnection? and why do you need it to be?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: class cast exception

 
0
  #5
Dec 27th, 2007
The stream connection is dervived from that class and therefore can be an instance of it. The connector class can be casted to any of its child / parents... hence the HTTPConnection instance etc... take a look at my pervious url link
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,616
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: class cast exception

 
0
  #6
Dec 28th, 2007
Before assuming anything just do a System.out.println(Connector.open(url).getClass()) and see which class instance are you actually trying to cast.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC