×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    10

    HttpConnection fails on x6

    Hi,
    I'm developing a mobile application for nokia x6. I am connecting to a server to read some data and i'm using http. From netbeans, when I run, it connects and displays the content of the link. However, when I run it on the phone, it fails with exception with message = -l;

    One thing I noticed is that a message pops up asking you if you want the app to access the network but I do not see the part were the user. In short, the midlet is unable to connect to an external ip. What am I doing wrong. I created 3 sample midlets with the same reqult.

    Below is some results:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package hello;

    import java.io.IOException;
    import java.io.InputStream;
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.TextBox;
    import javax.microedition.midlet.*;

    /**
    * @author Administrator
    */
    public class SecondExample extends MIDlet {
    private Display display;
    private String url =
    "http://www.javacourses.com/hello.txt";
    public SecondExample() {
    display = Display.getDisplay(this);
    }
    /**
    * startApp is invoked when
    * the MIDlet is activated.
    */
    public void startApp() {
    //The specified URL is overridden
    //in the descriptor
    try {
    downloadPage(url);
    } catch(IOException e) {
    // handle the exception
    }
    }
    private void downloadPage(String url)
    throws IOException {
    StringBuffer b = new StringBuffer();
    InputStream is = null;
    HttpConnection c = null;
    TextBox t = null;
    try {
    long len = 0 ;
    int ch = 0;
    c = (HttpConnection)Connector.open(url);
    is = c.openInputStream();
    len =c.getLength();
    if( len != -1) {
    // Read exactly Content-Length bytes
    for(int i =0 ; i < len ; i++ ){
    if((ch = is.read()) != -1) {
    b.append((char) ch);
    }
    }
    } else {
    //Read until the connection is closed.
    while ((ch = is.read()) != -1) {
    len = is.available() ;
    b.append((char)ch);
    }
    }
    t = new TextBox("hello again....",
    b.toString(), 1024, 0);
    } finally {
    is.close();
    c.close();
    }
    display.setCurrent(t);
    }
    /**
    * Pause, discontinue....
    */
    public void pauseApp() { }
    /**
    * Destroy must cleanup everything.
    */
    public void destroyApp(boolean unconditional) { }

    }


    thank you,

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: HttpConnection fails on x6

    The network call should be in a separate thread, rather then the main midlet life cycle method directly.

    Other check the network/GPRS settings on your X6, try downloading any test app from internet and see if connects. Try operamini, see if it opens the websites.

    thanks,
    Ekta

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    10

    Re: HttpConnection fails on x6

    Thanks for the response.
    I download opera mini from the ovi store some time back and on running I got the error "Failed to connect to the Internet".
    Also, I tried to install opera mini 5.0 and during installation I got the error "Authorization Failed".
    Visiting google with the internal browser works fine though. The thing is when using the inernal browser, it displays the "Connecting to ..." message and after connecting, the pages load. With opera nothing shows. The same for my midlets. It only asks if you want to allow the midlet to use network resource and nothing else.

    Is there a link or place I can go to get a solution to this?

    I connected to a wireless network and the application worked. Opera mini 4.2 also worked fine. When the wireless is off, it cannot connect nor does it ask me which one to use.
    Last edited by ritcoder; 2010-06-05 at 16:39.

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: HttpConnection fails on x6

    I download opera mini from the ovi store some time back and on running I got the error "Failed to connect to the Internet".
    If Opera Mini is also failing this means that j2me apps are able to connect to full internet, check the GPRS settings and for the application set the default access to full internet GPRS gateway access point and not the operator WAP gateway.

    Some operator's WAP gateway allows request from device browser to popular sites like google and OVI store etc.

    Which GPRS Access point you are using for testing, which operator ?
    Last edited by ektasrv; 2010-06-06 at 09:02.
    Thanks,
    Ekta

  5. #5
    Registered User
    Join Date
    Jun 2010
    Posts
    10

    Re: HttpConnection fails on x6

    Hi,
    You were right. There was something wrong with my gprs settings. In connectivity > Destinations, there is Internet, Multimediia msg., WAP services and Uncategorised. I defined a new packet data connect under internet and it worked. It appears from my application, it does not show the access points under Uncategorised.

    Thanks again.

    Richard.

  6. #6
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: HttpConnection fails on x6

    Nice to here that I could help you resolve the problem and was able to pinpoint the right Issue.
    Thanks,
    Ekta

Similar Threads

  1. j2me HttpConnection download fails
    By barbeNoire in forum Mobile Java General
    Replies: 11
    Last Post: 2010-07-26, 07:53
  2. HttpConnection fails after rebooting phone
    By dagfinn in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2009-03-10, 09:53
  3. HttpConnection throws NumberFormatException on Nokia 6600
    By saddamlennon in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2007-10-30, 19:51
  4. HttpConnection fails when app in background (onS60 phone) and WAP browser uses new AP
    By david_parry1976 in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2007-02-22, 16:37
  5. 6620 HttpConnection creation fails with "Symbian OS Error -18"
    By rmanheim in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2004-03-18, 17:57

Posting Permissions

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