简体   繁体   中英

Most classes (Scanner, Math, Calendar, Time) don't work for Java ME

I am EXTREMELY frustrated with the fact that after installing Java ME on Netbeans and trying to use the very vital classes that java provides, most of them don't work!

The other ones are do-able, but SCANNER?!!!? I can't even function without that (pardon the pun)

My code:

/*
 * To change this license header, choose License Headers in Project     Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package priorityapp.prioritize;
import java.util.*;
/**
 *
 * @author courtneymaroney
 */
public class test {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);

        Prioritize p = new Prioritize();
        System.out.println("Add a new event: ");
        String input = scanner.nextLine();
    }
}

Now, on it, it has an error that says "cannot find symbol" with NO suggestions for importing. This has happened for a very large variety of methods or classes that I have been trying to use, all being kind of the main reason for using java in the first place...

What should I do? Any suggestions?

JavaME has no main class. When creating MIDlets you have to extend the MIDlet class (just like you extend the Applet class when making Applets, or the HttpServlet class when creating Servlets, or the Xlet class when making Xlets).

The MIDlet class then has startApp() method, which is the method that runs when the app is started.

A few links to a Hello World example:

https://www.roseindia.net/j2me/hello-world.shtml

https://www.codeproject.com/Articles/169501/J-ME-Hello-World-Mobile-Application

Something to keep in mind, that I've been told many times by other JavaME developers: JavaME != Java

If you are using JavaME3 at least to retrieve some of your favorite java.util classes you can have a look to the BouncyCastle J2ME pack https://www.bouncycastle.org/latest_releases.html and especially its J2ME package https://www.bouncycastle.org/download/lcrypto-j2me-158.zip . There certainly exists more complete JavaME libs on the Web (where later JDK things were ported to ME3) but as I'm using this one...

Also you should have a look at JavaME extensions that are generally available for a large number of platforms, if your mobile platform supports some of them then the manufacturer has certainly pre-loaded or made available implementations of these extensions. For some use cases this will provide you with all the necessary tools to work. Check out https://en.wikipedia.org/wiki/Java_Platform,_Micro_Edition#Main_extensions and your target platform documentation.

Aside of that if you are using JavaME.8 then you are certainly more lucky :) More functions and tools should be available but honestly I did not have the chance to dive in yet.

Finally for your system input issue (in JavaME3) it is not so easy to make it work that way. Getting user input from an embedded device is typically system-dependent and it can take various forms (or none...). I'd suggest to investigate other alternatives of testing or use the provided debugger and emulators if any. Not the best suggestion certainly but if none of these is available and if you still require advanced testing features and smart user inputs you could extract a library from your JavaME app and include it in the classpath of another JavaSE app dedicated to testing that library. Your "JDK1.3" library will perfectly work into your JDK8 test-app...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM