在Activity中调用Runnable类

时间:2012-03-14 17:38:49

标签: java android runnable

我有一个Runnable类,是否可以在一个活动中调用这个runnable类?

这是我的班级:

public class TstClass implements Runnable {

static boolean m_bret = false; 
static String m_szconfig = "-i";
private int n_stat;
public native String unimplementedStringFromJNI();


static {
    try {
        System.out.println ( "[AdDBCache] Module load try ffmpeg : " + System.getProperty("java.library.path"));
        System.loadLibrary("tstjni");
        System.out.println ( "[AdDBCache] Module load success");

     } catch ( Exception e ) {
         System.out.println ( "[AdDBCache] Module load err : " + System.getProperty("java.library.path"));
}
}

private static synchronized final native int mod_run (String name, String sztoken );

public void set_config ( String sz_config ) {
    m_szconfig = sz_config;
}


public void run_core ( String sz_file, String sz_token ) {
    m_bret = false;
    n_stat = mod_run ( m_szconfig, sz_token );
    m_bret = true;
}


public void run () {
    run_core ("", "");
}

}

Logcat错误:

03-14 17:53:11.405: E/AndroidRuntime(2605): FATAL EXCEPTION: Thread-8
03-14 17:53:11.405: E/AndroidRuntime(2605): java.lang.UnsatisfiedLinkError: mod_run
03-14 17:53:11.405: E/AndroidRuntime(2605):     at com.parsapp.actionmovie.ffmpeg.mod_run(Native Method)
03-14 17:53:11.405: E/AndroidRuntime(2605):     at com.parsapp.actionmovie.ffmpeg.run_core(ffmpeg.java:31)
03-14 17:53:11.405: E/AndroidRuntime(2605):     at com.parsapp.actionmovie.ffmpeg.run(ffmpeg.java:37)
03-14 17:53:11.405: E/AndroidRuntime(2605):     at java.lang.Thread.run(Thread.java:1096)

2 个答案:

答案 0 :(得分:2)

您是否尝试过以下操作? 你遇到过任何问题吗?

TstClass tst = new TstClass();
new Thread(tst).start();

文档:http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html

答案 1 :(得分:0)

new TstClass().run(); 

应该工作。你试过吗?