views:

682

answers:

3

So, I'm using the HTTPConnection Class, like so:

HttpConnection c = 
    (HttpConnection)Connector.open("http://147.117.66.165:8000/eggs.3gp");

Following what LOOKS like the right way to do things in the Blackberry JDE API.

However, my code crashes if I try to do just about anything with the variable 'c'.

.getType()
.getInputStream()
.getStatus()

all cause it to crash.

I can, however get the URL from it, and I can look at the variable 'c' itself to know that it did, in fact, get created.

Did I manage to create a broken Connection? Do I need to do something else to actually do things with the connection? Under what circumanstances will this happen (I know the link is good, I can use the blackberry's browser to visit it).

Am I just using HttpConnection wrong? How would I do things correctly?

A: 

The API documentation for HttpConnection suggests the first call should be to c.getResponseCode(), try that.

Richard
A: 

What error is it throwing when it crashes? You may want to try adding the "Connector.READ_WRITE" as a second argument to your open call - even if it's just a "read only" connection like a GET, some OSes such as 4.6 will throw an exception unless you open it in read/write mode.

Marc Novakowski
Really? I think I'm using 4.6, but I'm not seeing any exceptions now...*ponder* Why would it even give you the ability to open it in a way that never works?
Jenny
+1  A: 

I figured out what was wrong by finding some sample code that was using HttpConnection, (at least, I think I did, at least, I can access all those variables, now). Before, I wasn't ever casting it as a "Stream Connection" (the examples I saw had it cast from Connector to HTTPConnection).

StreamConnection s = null;
s = (StreamConnection)Connector.open("http://10.252.9.15/eggs.3gp");
HttpConnection c = (HttpConnection)s;                        
InputStream i = c.openInputStream();
System.out.println("~~~~~I have a connection?~~~~~~" + c);
System.out.println("~~~~~I have a URL?~~~~" + c.getURL());
System.out.println("~~~~~I have a type?~~~~" + c.getType());
System.out.println("~~~~~I have a status?~~~~~~" + c.getResponseCode());
System.out.println("~~~~~I have a stream?~~~~~~" + i);
player = Manager.createPlayer(i, c.getType());

Even though the stream is now successfully being created, I'm still having problems USING it, but that might be because my connection is so slow.

Jenny
I don't think the casting is doing anything - you're not even using the "s" variable so you might as well be casting to HttpConnection and storing in "c". There's probably something else going on. If you could give us more information about the exception being thrown, it would definitely help.
Marc Novakowski
Before, I was getting a "JUM Error 104: Uncaught NullPointer Exception", but adding that cast gets rid of it entirely. My code claims a stream is sucessfully being created, but then it won't play the stream. From the debug messages, it THINKS it is playing it, but I see nothing.
Jenny