Reputation: 85
Is it possible to run an android app from a class with a main method, as a Java app?
I would like to test some classes written without using android libraries, and I would rather use System.out.println() than running the android emulator with the whole app.
I guess creating an extra project is a workaround, but I am wondering if there is a straightforward way of doing it.
I wrote:
Debug.java
package com.myapp.test;
public class Debug {
public static void main(String args[]){
System.out.println("Hello World!");
}
}
It gives the following error when I click, Run As -> Java Application:
Invalid layout of java.lang.String at value
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (javaClasses.cpp:124), pid=50304, tid=12920
# fatal error: Invalid layout of preloaded class
#
# JRE version: (8.0_05-b13) (build )
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.5-b02 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\ME\workspace\MyFirstApp\hs_err_pid50304.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
#
Upvotes: 0
Views: 51
Reputation: 2398
Usually, if I have code that is separate from my UI Toolkit (the Android SDK in your case) I would create a library project for it. It is a good practice anyways so that you ensure that your model and logic are totally separate from your UI with dependencies going only from the UI to the model, and not the other way around.
If you do that, then it would be trivial to test your UI-independent code. I would probably create a third project which will include your unit tests (which you should have)and, if needed, some test programs like the one you intend to write. It is not a lot of overhead to have the separate project and provides for a cleaner build process as well.
Upvotes: 1