开发者

J2ME with java 1.6

I'm using CLDC 1.1 + MIDP 2.0开发者_StackOverflow社区 . The "Compiler compliance level" is set to 1.4 .

When I set "Compiler compliance level" to 1.6, I get the following error: "ALERT: java/lang/ClassFormatError: Bad version information.".

How can I use java 1.6 with J2ME?


This answer maybe outdated now, please refer below for latest answers.


Date: April 2011

How can I use java 1.6 with J2ME?

You can't

Core Reason: J2ME is meant for mobile device where the memory & cpu are the biggest constraint.


Java ME is a subset of Java, and most of the ME specific code will reside mostly on the client, so you don't need any special versions of Java to compile the program.

The problem here is that you are using a version of Java compiler that didn't exist when the phone was invented. The version of the Java compiler is written to the .class compilation output.

Ideally you would compile the project with an older version of Java, but it is very hard to install an old version. So we can act as a compiler ourselves, and manually set the version in the .class output files to the version we desire, and we should make sure that we don't use features from after that version. In this case we will target version 1.2.

You can use the -source and -target options of the compiler to prohibit as many features as possible but many javac compilers have a limit to the older versions they can target, my Java 9 (1.9) can go as low as 1.6. You will need to manually ensure that you are not using features introduced between 1.2 and 1.6

The first 4 bytes in a .class file are the infamous "CAFEBABE" magic string. bytes 5 and 6 are usually 0 bytes 7 and 8 are the java minor and major versions.

Change Byte 8 to 0x2E. According to https://en.wikipedia.org/wiki/Java_class_file this corresponds to version 1.2 or Java2.

We are using Java2 because, as you can see in its initials J2ME, Micro Edition was released in Java 2. So for backwards compatibility reasons, you can be fairly confident that the phone will run such applications. If you need features introduced after this Java version, just keep increasing the version number until it fails again to find out the exact version of Java supported by your phone.


you can not use it because it is for se and ee version not compatible with mobile

latest sdk for j2me 3.0 is available

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜