×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    2

    Internet with 6288

    Hi:
    I'm new in J2ME programming and i've found a problem.
    I have a MIDlet that connects to a Servlet and sends and receives some Strings.
    My app works fine in a 6500 and all the 5th generation family, but I have a 6288 (3th?) and I can't make it work.
    The right moment I press "OK" for the "using connectivity" alert, it gives a NullPointerException.
    Hope somebody can help me.
    Here's the code of the connection:

    public HttpConnection daConexion() {
    HttpConnection c = null;
    System.out.println("Declarada HttpConnection en CreadorConexion.");
    try {
    c = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
    informacion = "Conexion creada";
    System.out.println("Obtenida conexión para el HC.");
    c.setRequestMethod(HttpConnection.POST);
    c.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT");
    c.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");
    c.setRequestProperty("accept-language", "en-CA");
    } catch (Exception conexionFailure) {
    System.out.println("Excepción al establecer la conexión para recibir: " + conexionFailure.getMessage());
    informacion = conexionFailure.getMessage();
    }
    return c;
    }

  2. #2
    Nokia Developer Expert
    Join Date
    May 2007
    Location
    Mexico D.F
    Posts
    351

    Re: Internet with 6288

    Hello

    1. What if you just use

    Code:
    c = (HttpConnection) Connector.open(url);

    2. Not clear to me why you get a NullPointerException,

    I would suggest to change

    Code:
    Exception conexionFailure
    by the corresponding exception and see if you are actually getting a IOException, then it could be a network configuration problem, you may also print the stacktrace, getMessage() is not allways enough

    3. If you are able to get connected, check out the response code to see if it is 200

    Code:
    int rc = c.getResponseCode();
    if (rc != HttpConnection.HTTP_OK) {
                     throw new IOException("HTTP response code: " + rc);
                 }
    3. Are you creating the connection in a separate thread?


    4. Do you actually need all those properties set and POST method? if not, why not making it simple

    Code:
    try {
                 c = (HttpConnection)Connector.open(url);
                 rc = c.getResponseCode();
                 if (rc != HttpConnection.HTTP_OK) {
                     throw new IOException("HTTP response code: " + rc);
                 }
    
                 is = c.openInputStream();
    Let us know how it goes
    Last edited by rdrincon; 2008-09-23 at 21:33. Reason: complementing
    :Ruben

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    2

    Re: Internet with 6288

    Hello.
    Thank you for your help! ¿¿Va bien por Méjico?? Soy de España
    Anyway, I'll go on using english so everyone can read this and learn.
    Quote Originally Posted by rdrincon View Post

    1. What if you just use

    Code:
    c = (HttpConnection) Connector.open(url);
    I tried but didn't work.

    Quote Originally Posted by rdrincon View Post
    2. Not clear to me why you get a NullPointerException,

    I would suggest to change

    Code:
    Exception conexionFailure
    by the corresponding exception and see if you are actually getting a IOException, then it could be a network configuration problem, you may also print the stacktrace, getMessage() is not allways enough
    The point is that I can't get any trace on the device. I've set a String to get all info and display it in a Form that comes visible everytime an exception is catch. But it just pops up this NullPointerException using the mobile api, not my trace.
    I used the Nokia S40 3th Gen emulator and it worked well. ARGH!

    Quote Originally Posted by rdrincon View Post
    3. If you are able to get connected, check out the response code to see if it is 200

    Code:
    int rc = c.getResponseCode();
    if (rc != HttpConnection.HTTP_OK) {
                     throw new IOException("HTTP response code: " + rc);
                 }
    As said just above, no way to know if I get connected, but it doesn't even show the "G" that indicates the use of GPRS connection, so I guess not.

    Quote Originally Posted by rdrincon View Post
    3. Are you creating the connection in a separate thread?
    Yes.
    Quote Originally Posted by rdrincon View Post
    4. Do you actually need all those properties set and POST method? if not, why not making it simple

    Code:
    try {
                 c = (HttpConnection)Connector.open(url);
                 rc = c.getResponseCode();
                 if (rc != HttpConnection.HTTP_OK) {
                     throw new IOException("HTTP response code: " + rc);
                 }
    
                 is = c.openInputStream();
    Yeah, I need them because the url has "?eleccion=movil" parts and it's not allowed to use them with GET and HEAD connections. (I got an error)
    The other settings... not really, but I don't think they can get a NullPointerException, do they??

    Thanks again!

Similar Threads

  1. Nokia 6101 Locked 2 TMobile Midlet can't access internet...
    By Jason Glass in forum Mobile Java Networking & Messaging & Security
    Replies: 45
    Last Post: 2007-11-14, 02:19
  2. S40 MIDP App with WAP and Internet APN
    By samir01m11 in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2007-08-08, 05:13
  3. E70 internet access through Mac Mini Airport
    By mbaar in forum General Development Questions
    Replies: 0
    Last Post: 2006-10-14, 18:11
  4. Connect Nokia 7650 Emulator to Internet via modem/RAS on Win2000/WinXP Pro
    By Youth_Jack in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2006-02-05, 17:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •