×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    28

    3650 httpconnection problem

    hi all:
    i have a problem with nokia 3650 httpconnection,my program runswell on others emulators like siemens 6688i,moto i85.html text content can be correctly read and shown. when it run on real 3650,no html text content is shown.the program is very simple,using a httpconnection to get a page's text content and show it in a form.
    the code:

    package httptest;

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    import java.io.*;

    public class httpTest extends MIDlet {
    private Display display;
    private CommandThread commandThread;

    public httpTest() {
    display = Display.getDisplay(this);
    }


    public void startApp() {
    commandThread = new CommandThread(this);
    commandThread.start();
    }


    public void pauseApp() {
    }


    public void destroyApp(boolean unconditional) {
    }


    public static void quitApp() {

    }
    class CommandThread extends Thread{
    MIDlet parent;
    public CommandThread (MIDlet parent){
    this.parent = parent;
    }
    public void run(){
    try{
    String url = "http://216.239.51.99/index.html";
    HttpConnection sc = (HttpConnection)Connector.open(url);
    DataOutputStream dos = new DataOutputStream(sc.openOutputStream());
    DataInputStream dis = new DataInputStream(sc.openInputStream());
    String contant = "";
    int ic;
    while((ic = dis.read())!= -1){
    contant = contant + (char)ic;
    }
    Form f = new Form("new http test");
    f.append(contant);
    display.setCurrent(f);
    }
    catch(Exception e){
    System.out.println(e.getMessage());
    notifyDestroyed();
    }
    }

    }


    }

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    393
    It is because of the DataOutputStream that has been created.

    Some general recommendations:

    - Close the streams in a finally block
    - Use Stringbuffer to append the characters forming the string to minimise string object creation and therefore heap usage.

    [N]/Forum Nokia
    Last edited by nmittal; 2003-07-14 at 07:24.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    28
    can you tell more in detail,what's wrong with the DataInputStream?

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    393
    Comment out the DataOutputStream line and it should work. Nothing is wrong with the DataInputStream.

    [N]/Forum Nokia

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    28
    i run the program on real phone 3650,i notice that i can not show
    the Form with the title "new http test",so i don't know if it has read the text content from the page. the program quit itself after
    about 20 seconds.can you tell me why?

  6. #6
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    393
    I tried on 3650 (v3.13) after commenting out the line mentioned earlier and it worked fine. It is also recommended to close the connection and streams in a finally block.

    Regards,
    [N]/Forum Nokia

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    28
    i solve the problem as you according to your recommendation.

Posting Permissions

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