J2ME emulator does not appear to open in Eclipse - eclipse

I currently have Java ME SDK 3.0.5 installed and am running a MIDLET from Eclipse.
When I run the app under the emulator device I get the following data in the console:
Syntax:
emulator [arguments]
In order to get commands supported by given device run:
emulator.exe -Xdevice:<device name> -Xquery
Generic list of arguments is:
-version Display version information about the emulator
-help Display list of valid arguments
-classpath, -cp The class path for the VM
-D<name>=<value> Set a system property
-Xdebug Use a remote debugger
-Xrunjdwp:[transport=<transport>,address=<address>,server=<y/n>,
suspend=<y/n>]
Debugging options
-Xdevice:<device> Select a device skin for the emulator
-Xdomain:<domain_name>
Set the MIDlet suite's security domain
-Xmain:<main class name>
Run the main method of a Java class, as in Java SE
-Xquery Print device information
Everything seems to be alright, but I can't get any form of emulation to appear.
here is the code of my MIDLET, although I don't think the problem lies here.
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
public class Hello extends MIDlet implements CommandListener {
private Command exitCommand;
private Display display;
private Form screen;
public Hello() {
display = Display.getDisplay(this);
exitCommand = new Command ("Exit", Command.EXIT, 2);
screen = new Form ("Hello World");
StringItem strItem = new StringItem ("","Hello World");
screen.append (strItem);
screen.addCommand (exitCommand);
screen.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
// set the current display to the screen
display.setCurrent(screen);
}
public void pauseApp() {
// TODO Auto-generated method stub
}
public void destroyApp(boolean unconditional) {
// TODO Auto-generated method stub
}
public void commandAction (Command c, Displayable s)
{
if (c == exitCommand)
{
destroyApp (false);
notifyDestroyed();
}
}
}

The output is pretty simple, it's telling you that the command line syntax to the emulator is incorrect.
Go to the Java ME device settings and edit the emulator command line / start options to suit.
Switching IDE's may work for you as a short-term fix, but it's always better to get to the root of the issue. Plus it'll help you understand the emulator framework.

I switched over to Netbeans, which has integrated support for J2ME (as opposed to having to install a 3rd party plugin for Eclipse) and it now works perfectly.

I had a similar problem while running a basic JavaMe app on eclipse, "Corrupt JAR, error while reading". It worked for me after I followed this series for starters http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.mtj.doc.user/html/gettingstarted/prepare_workbench.html (try not to miss anything mentioned here).
Note, when you launch the app, use "Launch as emulated Java ME JAD"(-in the top right "Running" section on the page) from the "Application descriptor" (-from left menu.)
This is a late reply but might just help someone in future.

If you are adventurous and want to develop / run JavaME application without IDE's than I have some ray of hope, write a batch script (or shell script for linux system) to manually run the emulator with specific jad
Batch Script (run.bat)
"<javame-3.0-sdk-root-folder>\bin\emulator.exe"
-Xdescriptor:"<jad-filename-with-extension>" >> logs.txt
pause
exit
save the above script in the same folder as the application jad/jar. The console prints will be available in log.txt file.

Here is post how to run jar from emulator (Java ME SDK 3.0.5)
(How to run MIDLET in Java ME SDK 3.0.5 ::http://madhukaudantha.blogspot.com/2012/10/how-to-run-midlet-in-java-me-sdk-305.html

Related

Error when calling Native Code using JNI from a Jython module

I am calling a simple HelloWorld program written in C from a Jython module (inside a PyDev project). There is an intermediate Java Class (in a separate Java project) which calls the native code using JNI (Java Native Interface). The native call is successful if I run the Java class directly. But when I call the Java class from my Jython module, I get the following error:
java.lang.UnsatisfiedLinkError: no ctest in java.library.path
I have successfully run several C programs from my Jython module using JNA (Java Native Access). But JNA hits performance (speed) really hard and I want to revisit JNI and fix this problem (also I simply want to know what is going on). The IDE I am using is Eclipse.
Here is the code for the Java class:
package JNIPackage;
public class HelloWorld {
native void helloFromC(); /* (1) */
static {
// Added the line below but still no luck. Was sure this would fix it.
System.setProperty("java.library.path", "/Users/haiderriaz/Desktop/JNI-C");
System.loadLibrary("ctest"); /* (2) */
}
static public void main(String argv[]) {
HelloWorld helloWorld = new HelloWorld();
helloWorld.helloFromC(); /* (3) */
}
}
Running this Java class directly, there is no error and "Hello World" gets printed out. But when I import JNIPackage to my Jython module and then call JNIPackage.HelloWorld, then all of a sudden java can not find ctest. I think this is strange and the problem only exists when calling C code using JNI as opposed to JNA.
Try System.load([full path and filename of ctest]), which works independently from values of LD_LIBRARY_PATH or java.library.path.
To ease user configuration I usually implement my own library-search-mechanism, i.e. make it look for libraries in the working directory and on the classpath too. I know ideologically this is somewhat wrong, but works much smoother for your users. Use java.io.File.exists to confirm the actual location of ctest-file and then use java.io.File.getAbsolutePath() to get the appropriate input for System.load.
System.mapLibraryName(...) can also be useful for this.

Appbundler JDK8 MacOS Set WorkingDirectory Inside Package

Hi everyone !
I'm facing a problem since I'm migrating my app from Java6 to Java8 for MacOS (and other OS but with windows/linux there is NO problem !).
When I was using Java6 I used MacOS APP "App Bundler" to do the package.
This tools reference to a plist file that contains all package information and provide the ability to add an option "WorkingDirectory" and a variable $APP_PACKAGE to set the working directory of the package inside the package like that:
<key>WorkingDirectory</key>
<string>$$APP_PACKAGE/Contents/Resources/Java</string>
Unfortunately, this option "WorkingDirectory" does not exist with the bundler appbundler that provides support for Java 6 superior versions.
So I googled a lot and found this issue; Apple Issue
So I added <option value="-Duser.dir=$APP_ROOT/Contents/Resources"/> to my plist file via ant task like that:
<key>JVMOptions</key>
<array>
<string>-Xdock:icon=Contents/Resources/${bundle.icon}</string>
<string>-Duser.dir=$APP_ROOT/Contents/Resources</string>
</array>
And I tied also this:
<option value="-Duser.dir=$APP_ROOT/Contents/Java" />
<argument value="-Duser.dir=$APP_ROOT/Contents/Java"/>
Without success :-(
And I added a big "verrue" on early start of my Java application like that (as said here):
String os = System.getProperty("os.name").toLowerCase();
System.out.println("os:" +os);
if (os.indexOf( "mac" ) >= 0){
try {
System.setProperty("user.dir", new File(".").getCanonicalPath());
System.out.println("user dir:" +System.getProperty("user.dir"));
System.out.println(new File(".").toURI());
System.out.println("Working directory: "+(new File(".").getCanonicalPath()));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
But nothing works; when I was creating file from the previous Java application they were created into the application working dir like /Applications/MyApp.app/Content/Java, but know when I create a file/folder it is created under /Users/MyUserName
I also follow this PATCH (I post a question) and compile a new jar but the <string>-Duser.dir=$APP_PATH/Contents/Java</string> does not do the job, the env variable is not user system created and used!
It's driving me silly... Any idea ? Regards !!
[EDIT1] As a workaround and because it is also simple but too bad I just changed all my relative paths (some at least !) like that:
String path = new File(".").getCanonicalPath();
File myFile = new File(path+File.separator+"MyFile");
It acts similar to set the working directory variable but I have to change a lot of my code rather than use a single option (and on Linux and Windows I do not have this type of problem) :-( Anyway thanks to Trejkaz to have answer on my issue... and sorry for my misspellings and my poor English.
Another time, Regards !!
[EDIT2] So I edited all my relative paths but I had a second problem with the appbundle: Every ProcessBuilder commands fails when launched by the bundle but succeed when clicking on the jar so I used "desktop" intead like this:
DesktopApi desktopApi = new DesktopApi();
desktopApi.open("path-to-my-jar"+File.Separator+"MyJar.jar");
I use the class 'DesktopApi' found here coded by MightyPork (Regards !!) as sometimes desktop command provided by JRE fails...
So I'm done with this fu***** packaging now !!! Regards !!

Bouncy Castle (with Eclipse) - Source not found Error

I'm new to Bouncy Castle and have installed it using these instructions:
http://www.itcsolutions.eu/2011/08/22/how-to-use-bouncy-castle-cryptographic-api-in-netbeans-or-eclipse-for-java-jse-projects/
http://www.developer.com/java/other/article.php/3778011/Unlocking-the-Secrets-of-Java-Cryptography-Extensions-The-Basics.htm
Both links describe the steps to
Step 1. Download the Bouncy Castle provider
Step 2. Copy the provider .jar file to the Java Runtime (JRE) extensions subfolder
Step 3. Add the Bouncy Castle provider to the java.security file
As per the first set of instructions, I can run this code and it correctly gives me the "is available" response:
import java.security.Security;
public class Main {
public static void main(String[] args) {
//BC is the ID for the Bouncy Castle provider;
if (Security.getProvider("BC") == null){
System.out.println("Bouncy Castle provider is NOT available");
}
else{
System.out.println("Bouncy Castle provider is available");
}
}
}
The problem is that once I add anything else to the code, like for example this line:
KeyGenerator keygen = KeyGenerator.getInstance("DES/ECB/PKCS5Padding");
or even this line
KeyGenerator keygen;
it then crashes. In the debug mode, it gives me a "Source not found." error with the button to "Edit Source Lookup Path...". The tab that contains the error message says "CEStreamExhausted(Throwable).() line 249".
Can anybody tell me what I'm doing wrong? This problem has been driving me crazy for days!
I no longer need this question answered. When I wrote this post, I had only followed the directions for the lastest version of Java that I had installed (both JRE and JDK 7). Since then, I decided just to try also following the directions for JRE 6, which I had installed but wasn't using. I also made sure to reboot my laptop. It works now. Sometimes it's the simple things... sigh

Java - running cmd

I'm trying to run a simple java test code. I'm getting a "can not find or load main class file "(something like that)
The tutorial I'm following uses this command
-> javac name.java (javac doesn't work, using ->java ..)
-> dir (shows the classname as a file)
> java classname
> outputs "hello world"
I can't seem to get past the ->java running.java
class apples //everything begins with a class - need this to do anything
{
public static void main(String args[])//method
{
System.out.println("Hello World");
}
}
There could be a few problems here. Check the following:
Are you saving the file as the name of the class plus .java, e.g. apples.java
When you execute it, are you typing the name of the class or the name of the class file? you should be typing java apples, not java apples.class or java apples.java.
EDIT:
I Noticed you haven't compiled the program using javac, which makes the progrm unrunnable by java [program_name]. You need to run javac [java_sourcde_file_name] to generate a .class file. If javac doesn't work, maybe:
You don't have the JDK (Java Development Kit) installed and should download it from Oracle
javac is not in your PATH - unlikely but possible - see http://www.apl.jhu.edu/~hall/java/beginner/settingup.html.
javac runs properly but your program doesn't compile properly. this seems unlikely given the program you posted looks fine.
class Apples //- need this to do anything
{
public static void main(String args[])//everything begins with a method
{
System.out.println("Hello World");
}
}
Make sure you are in current directory of java file
compile as
javac Apples.java
Run as
java Apples
Before working in it , should need to know the coding convention it would be better to work java
Well. All you have to do in Jaca is navigate you where your class files are stored and then use java "class name". You DO NOT need to put .java or .class. Just the name.
change your class name from apples to Apples (naming convention for java class names):
http://en.wikipedia.org/wiki/Naming_convention_%28programming%29#Java
also recommend you to change the file name accordingly...
then recompile and run it
javac Apples.java
java Apples
cheers

Debug some PhpUnit tests in Eclipse

I use Eclipse PDT for PHP.
I can run my PhpUnit tests : works fine.
But I can not debug my unit tests.
Has someby already done this ?
Can somebody help doing this ?
Thanx,
Messaoud
An example is more worth than 1000 words :
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
class MyTestCase extends PHPUnit_Framework_TestCase {
protected function setUp() {
parent::setUp ();
}
function testSimple() {
echo "horray !";
}
protected function tearDown() {
parent::tearDown();
}
static function main() {
$suite = new PHPUnit_Framework_TestSuite( __CLASS__);
PHPUnit_TextUI_TestRunner::run( $suite);
}
}
if (!defined('PHPUnit_MAIN_METHOD')) {
MyTestCase::main();
}
the key thing is :
provide a main method in your testcase
test if the test is executed directly (via php MyTestCase.php) or by phpunit itself. if executed directly - just start the testrunner.
know you can debug your testcase.
We can solve this issue with our Eclipse plugin MakeGood.
MakeGood provides a simple way to debug your tests. You only run a test in Debug Mode.
For more information, see the user guide.
For others who are wondering if there are simple instructions for configuring Eclipse/Aptana with phpunit, here's a website I have found:
http://pkp.sfu.ca/wiki/index.php/Configure_Eclipse_for_PHPUnit
What you have to do basically is:
Make sure your PEAR libraries are in your project's include path. Right click on the project in the navigator window and click Properties. You'll see there's a section for PHP Include Path (or PHP Build Path in Aptana for my version), open that and add your PEAR libraries to your include/build path so that Eclipse knows about phpunit.
Create a debug configuration which runs the phpunit.php file (you might need to add the .php extension to the file if it is running with a shebang, as the case is in Mac OS X).
So with phpunit.php file as the "Start Action" script, set "PHP Script Arguments" so that the PHPUnit testing file you are interested with is run by phpunit.php. Add any other command line arguments, to suit you. eg. --verbose is a good option. You can also use variables like ${resource_loc} to have Eclipse replace it with the current file for example.
Run your debug configuration and enjoy debugging!
You do not need to modify your test files or anything, they'll work out of the box.
I finally run debugging parallel to command line in eclipse 3.4. Debugging i run as "PHP web page", my minimal code
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
class XTest extends PHPUnit_Framework_TestCase{
public function testX(){
//...
}
}
if (!defined('PHPUnit_MAIN_METHOD')) {
header('Content-type:text/plain; charset=utf-8');
PHPUnit_TextUI_TestRunner::run( new PHPUnit_Framework_TestSuite( 'XTest'));
}
I have confirmed by setting a breakpoint in my setUp() method inside my unit test by following the instructions here:
How to Debug Your PHP Unit Tests in Eclipse
It involves copying the /usr/bin/phpunit file to your project (so it's accessible through eclipse's GUIs), and add the .php extension to it. From there, goto your debug configs and set the PHP-File to that phpunit.php file.
The next important step worked great for me, because I'm using Yii which provided me with a bootstrap.php file. Put something like this in your args:
--bootstrap=${workspace_loc}/my-project/trunk/protected/tests/bootstrap.php ${workspace_loc}/my-project/trunk/protected/tests/unit/SomeClassToTest.php