Results 1 to 3 of 3

Thread: ทำไมโค้ดโหลดภาพไม่ขึ้นครับ

  1. #1


    นี่เป็นโค้ดที่ผมเขียนขึ้นเองนะครับ
    ผมจะโหลดภาพจากเวบนี้แหละขึ้นไปแสดงในมือถือ
    แต่มันทำไม่ได้
    ใครพอรู้ปัญหาของมันช่วยบอกทีเถิดกลุ้มมาก
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;

    public class connector extends MIDlet implements CommandListener, Runnable{

    private Display mDisplay;
    private Form mForm;
    public connector() {
    mForm = new Form("Connecting...");
    mForm.addCommand(new Command("Exit", Command.EXIT, 0));
    mForm.setCommandListener(this);
    }
    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    }
    protected void pauseApp() {
    }
    protected void startApp() throws MIDletStateChangeException {
    if (mDisplay == null) mDisplay = Display.getDisplay(this);
    mDisplay.setCurrent(mForm);
    Thread t = new Thread(this);
    t.start();
    }
    public void commandAction(Command c, Displayable s) {
    if (c.getCommandType() == Command.EXIT)
    notifyDestroyed();
    }
    public void run() {
    HttpConnection hc = null;
    DataInputStream in = null;
    try {
    //ผมเดาว่าปัญหามันเกิดจากตรงนี้ตรงค่าของการgetAppProperty แต่ไม่รู้ต้องแก้กันยังไง
    String url = getAppProperty("http://pic.citecclub.org/out.php/i2335_CitecclubBlack.png");
    hc = (HttpConnection)Connector.open(url);
    int length = (int)hc.getLength();
    byte[] data = null;
    if (length != -1) {
    data = new byte[length];
    in = new DataInputStream(hc.openInputStream());
    in.readFully(data);
    }
    else {
    // If content length is not given, read in chunks.
    int chunkSize = 512;
    int index = 0;
    int readLength = 0;
    in = new DataInputStream(hc.openInputStream());
    data = new byte[chunkSize];
    do {
    if (data.length < index + chunkSize) {
    byte[] newData = new byte[index + chunkSize];
    System.arraycopy(data, 0, newData, 0, data.length);
    data = newData;
    }
    readLength = in.read(data, index, chunkSize);
    index += readLength;
    } while (readLength == chunkSize);
    length = index;
    }
    Image image = Image.createImage(data, 0, length);
    ImageItem imageItem = new ImageItem(null, image, 0, null);
    mForm.append(imageItem);
    mForm.setTitle("Done.");
    }
    catch (IOException ioe) {
    StringItem stringItem = new StringItem(null, ioe.toString());
    mForm.append(stringItem);
    mForm.setTitle("Done.");
    }
    finally {
    try {
    if (in != null) in.close();
    if (hc != null) hc.close();
    }
    catch (IOException ioe) {}
    }
    }
    }

  2. #2
    Administrator asylu3's Avatar
    Join Date
    Jun 2000
    Location
    Thailand
    Posts
    3,557



    มี Error/Exception อะไรแสดงออกมาไหมครับช่วย Post บอกด้่วยเพราะตอนนี้เอา J2MEtoolkit ออกไปแล้วคง Run ไม่ได้




    ใช้ Tag BBcode ด้วยนะครับเวลา Post sourcecode มันจะได้อ่านง่าย
    <code></code>

    ปล. เปลี่ยน < เป็น [, และ > เป็น]

  3. #3


    อ้อผมแก้ได้แล้วครับ
    เอามาบอกเผื่อทุกคนเจอปัญหานะครับ
    อย่างที่บอกครับปัญหาอยู่ตรงนี้จริง
    ต้องเปลี่ยนเป็น
    **Hidden Content: To see this hidden content your post count must be 3 or greater.**
    แทนที่ตรีงบรรทัดของการทำ getApp นะครับ

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

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