Code J2ME bị lỗi

em có class Main{}

package dienthoaithongminh;

import javax.microedition.midlet.*;

/**
 * @author vovan
 */
public class Main extends MIDlet {
 public static MIDlet h;

    Main(){
        h=this;
    }
    public void startApp() {
        
     new BatDau();
    }
    
    public void pauseApp() {
        
    }
    
    public void destroyApp(boolean unconditional) {
        
     
    }
    
}

Rồi Class BatDau{ } như này

package dienthoaithongminh;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;

public class BatDau extends Canvas {

    private Image v = null;
    private ImageItem v1 = null;
    private int x = 75, y = 99;

    public BatDau() {
        try {
            v = Image.createImage("/begin.png");
        } catch (Exception tt) {
            System.out.println("lỗi " + tt.getMessage());
        }
        Display.getDisplay(Main.h).setCurrent(this);
    }

    protected void paint(Graphics g) {
        g.setColor(255, 0, 0);
        g.drawImage(v, 0, 0, Graphics.LEFT + Graphics.TOP);
        g.drawRect(x, y, 170, 45);
    }

    protected void keyReleased(int key) {
        int k = super.getGameAction(key);
        if (k == DOWN) {
            y = y + 60;
        }
        if (y > 219) {
            y = 99;
        }
        if (k == UP) {
            y = y - 60;
        }
        if (y < 99) {
            y = 219;
        }
        super.repaint();

    }

}

khi em chạy lên thì nó lỗi như này ạ


Nhưng khi mà em thay đổi class Main{} như này ạ

package dienthoaithongminh;

import javax.microedition.midlet.*;

/**
 * @author vovan
 */
public class Main extends MIDlet {
 public static MIDlet h;

    public void startApp() {
     h=this;
     new BatDau();
    }
    
    public void pauseApp() {
        
    }
    
    public void destroyApp(boolean unconditional) {
        
     
    }
    
}

thì nó lại chạy được ạ


AI GIẢI THÍCH GIÚP EM VỢI Ạ
EM CẢM ƠN Ạ

A post was merged into an existing topic: Topic lưu trữ các post off-topic - version 3

Định nghĩa cũ của midlet:

IllegalAccessException: Thrown when an application tries to load in a class, but the currently executing method does not have access to the definition of the specified class, because the class is not public and in another package.

đoán mò ko có quyền access vào Main() constructor. Thử thêm public Main() xem hết lỗi hem

9 Likes

cảm ơn mình fix lỗi được rồi

Sự nghiêm túc của J2ME khi gọi hàm dựng mặc định từ java.lang.reflect.Constructor.

7 Likes

ok bạn , mình bắt đầu học nên ngu lắm, dốt tiếng anh , 1 lần đọc tài liệu từ google dịch nên chả hiểu gì luôn

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?