• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to compile code from string(with exec)

Your question isn't that clear. Could you explain what you're trying to do?
 
File Example2 text:
//////////////
import java.util.*;
public class Example2 { public static void main(String args[]) { System.out.println(1234567); } }

Main program text:
/////////////////
import java.util.*;
public class Main
{
public static void main(String[] args)
{
try{
Runtime.getRuntime().exec("/storage/emulated/0/AppProjects/MyJavaConsoleApp/src/Example2.java");}
catch (Exception e){}
}
}

//////////Do not wait, fail
 
Runtime.getRuntime().exec("/storage/emulated/0/AppProjects/MyJavaConsoleApp/src/Example2.java");

That's not going to work. I think you misunderstand how to use the exec() method of Runtime. The string parameter is the path to an executable (binary) file within the filesystem.
Simply specifying a Java source file won't work and would probably generate an exception.

Plus you have a basic misunderstanding of how an Android app is constructed, because you never define a main() method. Android apps run as a thread of execution, within the Dalvik JVM runtime framework. The entry point for any app is via the onCreate() method.
 
That's not going to work. I think you misunderstand how to use the exec() method of Runtime. The string parameter is the path to an executable (binary) file within the filesystem.
Simply specifying a Java source file won't work and would probably generate an exception.

Plus you have a basic misunderstanding of how an Android app is constructed, because you never define a main() method. Android apps run as a thread of execution, within the Dalvik JVM runtime framework. The entry point for any app is via the onCreate() method.
How to use Dalvik for compiling, building, runing program.?
 
Back
Top Bottom