Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User carlos_online's Avatar
    Join Date
    Oct 2003
    Posts
    1
    Folks...

    I used a code I got from a Sun's tutorial to make my mobile phone fetch an internet page reading a file. The code is down under.
    Okay. I developed the code using JBuilder 9 and it create two files: a JAR and a JAD.
    What is JAD for?? Must I put it in my mobile phone, too???
    So... the program runned perfectly in the JBuilder's emulator, however when I downloaded it to the mobile phone Nokia 7650 the program crashed saying that a error has ocurred and that's why the program was going to exit. =(
    Did anyone see this happened??? It's weird because it works perfectly in the emulator!!! If anyone knows the answer I will be very thankful.

    Follows the source code:

    package monitoracao;

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

    /**
    * Um MIDlet que abre uma pagina usando uma HttpConnection.
    */
    public class MIDlet1 extends MIDlet {

    private Display display;
    private String url = "http://www.javacourses.com/hello.txt";

    public MIDlet1() {
    display = Display.getDisplay(this);
    try {
    jbInit();
    }
    catch(Exception e) {
    e.printStackTrace();
    }
    }

    /**
    * Isso sera chamado quando This will be invoked when we activate the MIDlet.
    */
    public void startApp() {
    // Use the specified URL is overriden 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 till the connection is closed.
    while ((ch = is.read()) != -1) {
    len = is.available() ;
    b.append((char)ch);
    }
    }
    t = new TextBox("Monit. Fatura", 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) {
    }
    private void jbInit() throws Exception {
    }

    }

    Yours Truly,

    Carlos
    carlos_online@ig.com.br

  2. #2
    Registered User wbb826's Avatar
    Join Date
    Jul 2005
    Location
    Guangzhou, China
    Posts
    26
    1. Can you run the JAD in your PC by just double click?
    2. Application need to be installed before running in your REAL phone.
    3. Check whether incompatables exit.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved