Skip to main content

ClassCastException: (net.jxta.pipe.PipeID) IDFactory.fromURI(fromUri)

4 replies [Last post]
davjoh
Offline
Joined: 2007-07-18
Points: 0

<br />
 net.jxta.pipe.PipeID pipeId = null;<br />
try {<br />
   URI fromUri = new URI(pipeIdString);<br />
   pipeId = (net.jxta.pipe.PipeID) IDFactory.fromURI(fromUri);<br />
} catch (URISyntaxException uriEx) {<br />
    uriEx.printStackTrace();<br />
}<br />

is giving me

java.lang.ClassCastException: net.jxta.impl.id.UUID.PeerID cannot be cast to net.jxta.pipe.PipeID

Any ideas? I've checked my imports, I've checked the value of pipeIdString, and both are correct. I don't really know what else to do now. Or is this a bug?

Using the 2.5 binary from jxta.dev.java.net downloads.

-David

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
adamman71
Offline
Joined: 2007-01-31
Points: 0

Pipes always belong to peer groups, you should use:

IDFactory.newPipeID(PeerGroupID groupID, byte[] seed)

to create your pipe ID. You should set:

seed = IDFactory.fromURI(fromUri).toString().getBytes();

That should solve your issue.

J.

davjoh
Offline
Joined: 2007-07-18
Points: 0

Hi J,

Thanks - and good point there. What I was trying to do was recreate the PipeID from a pipeID of a unicast pipe passed as a String via a propagate pipe so I know how to talk back to the unicast pipe from the sending peer.

But I guess what I can do it pass a seed via the propagate pipe and do it the way you've described.

But there's no reason the code I posted initially shouldn't work, is there??

-David

davjoh
Offline
Joined: 2007-07-18
Points: 0

Aaaah nevermind... I just realised I wasn't passing a pipe ID but a peer ID which was probably the problem...

adamman71
Offline
Joined: 2007-01-31
Points: 0

Mmmm, I am not really sure what you are trying to do with your pipe IDs, but one thing is sure, calling IDFactory.fromURI(...) will return an ID and you are trying to cast it into a PipeID.

Don't forget that ID is an interface, not a class, and that PipeID is an abstract class extending the ID interface. The object returned by IDFactory will implement the ID interface for sure, but it won't necessarily be a subclass of PipeID.

I bet Java is tilting at compile time for you.

Cheers,

J.