Results 1 to 6 of 6

Thread: Java ClassCastException

  1. #1
    Join Date
    Mar 2010
    Posts
    184

    Java ClassCastException

    Hello,
    I like to make a UserNodeData object called via RMI from a server to a client. In the client part, I created an object of type interface UserNodeData interface.
    Here is the my code
    Code:
    RemoteLinkman ser;
    Public void display(Graph g) throws RemoteException {
       usrnddt = d (usrnddt)ser.getRootNode();
       Usernode node = new Usernode(d, g,this);
       node.afficherLesVoisins(5);
    }
    I begin by starting the server and then I run the client. After that the connection is established, it produces the error. I have do not have much idea about the error. If you can help on this then it would be great. Thanks in advance.
    www.techarena.in

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Java ClassCastException

    Hello,
    The method
    Code:
    "ser.getRootNode ();"
    do not you simply returns an object of type "usentdt" so your cast throws an exception
    And I would add that:
    1) the error message is explicit
    2) The problem is easy and you can do the needful.
    This should not have much problem for you.

  3. #3
    Join Date
    Dec 2009
    Posts
    202

    Re: Java ClassCastException

    Hello,
    I have a similar kind of problem and here is my code, please help me with this and if you find a problem in my code then please guide me with the correct.
    Code:
    Public class ndmnser extends UnicastRemoteObject implements RemoteLinkman {
     
    	private static Final long serialVersionUID = 1L;
    	Public ndmnser()  throws RemoteException  {
    	}
    	Public UserNodeData getRootNode() throws RemoteException
    	{
    		Connection c = Link.getSQLcon().getConnection();
    Statement st;
    
    		/ / Get a Statement object
    		try {
    			st = c.createStatement();
    String u = "laurent";
    String q = "SELECT * FROM u WHERE username = '" + User + "'";
    ResultSet rs = st.executeQuery(q);
    System.err.System.out.println(q);
    			if (rs.next()) {
    		
    				UserNodeData n = new UserNodeData (rs.getString("firstname")  , rs.getString("name"), Rs.getString("username"), rs.getLong("id"));
    System.out.System.out.println("what is returned by getrootnode" + N);
    				return n;
    			}
     
    		} catch (Exception e)
    		{
    			e.printStackTrace();
    		}
    		System.err.System.out.println("return null");
    		return null;
     
    	}

  4. #4
    Join Date
    Nov 2009
    Posts
    343

    Re: Java ClassCastException

    Hello,
    In this case, have you checked that the item is serializable, so that all sub-objects that compose it? Otherwise, it is normal that it does not pass properly through RMI. As you do quite the same. Class files on the server side and client side or are they and generated with different JVM: this could explain the lack of your client-side object. I hope you are getting the point what I have explained here.

  5. #5
    Join Date
    Mar 2010
    Posts
    184

    Re: Java ClassCastException

    Hello,
    I have done a modification to the above code and I am try to customize the code for my needs.
    Here is my code.
    Code:
    Public class usrnddt extends UnicastRemoteObject implements LinkNodeData {
    	
     
    	private static Final long serialVersionUID = 1L;
    	
    	private String frnm;
    	private String lsnm;
    	private String usnm;
    	private String url;
    	private long id;
    	
    	Public Final static int type = LinkNodeData.Usernode;
     
     
    	Public usrnddt (String frnm, String lsnm, String usnm, long id) throws RemoteException
    	{
    		this.frnm = Firstname;
    		this.lsnm = Lastname;
    		this.usnm = Username;
    		this.url = "c: / intero.jpg";
    		this.id = Id;
    
    	}
    If you have a find any problem in my code, then please correct it and post back. Thanks in advance.
    www.techarena.in

  6. #6
    Join Date
    Dec 2009
    Posts
    211

    Re: Java ClassCastException

    Hello,
    I do a the following code
    Code:
    ArrayList arr = new ArrayList();
    arr.add(new URL("file:/test"));
    String u = (String) arr.get(0);
    And I get the following error that the same error which is posted here. So, this code is related to the topic.
    Here is the error which I get
    Code:
    java.lang.ClassCastException: java.net.URL
    I have no idea about the error, I would be pleased if you you help me with this. Thanks in advance.

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2013, 11:04 PM
  2. Comparison between core java and advanced java
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 19-01-2010, 10:57 AM
  3. How big is an Object in Java? Why Java neglects sizeof?
    By KALINDA in forum Software Development
    Replies: 4
    Last Post: 10-11-2009, 03:19 AM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,847,343.72260 seconds with 16 queries