Exception in thread "Thread-0" java.lang.RuntimeException: Stub! at android.util.Log.i(Log.java:...

1.测试代码如下

class ThreadTest2  extends Thread{
    private int i ;
    // 上一个线程
    private Thread previousThread;

    public ThreadTest2(int i, Thread previousThread) {
        this.i = i;
        this.previousThread = previousThread;
    }

    @Override
    public void run() {
        super.run();
        try {
            previousThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

       Log.i("cyp", "run: "+i);
    }

    public static void main(String[] args) {
        Thread previousThread = Thread.currentThread();
        for (int i = 0;i < 10;i++){
            ThreadTest2 threadTest2 = new ThreadTest2(i,previousThread);
            threadTest2.start();
            previousThread = threadTest2;
        }

    }
}

2.运行后报错:

Exception in thread "Thread-0" java.lang.RuntimeException: Stub!
    at android.util.Log.i(Log.java:102)
    at threadtest.ThreadTest2.run(ThreadTest2.java:28)

3.原因:import android.util.Log;这里用的是Android的库,在java中是不能这么用的。
4.解决方法:
在java中应该用System.out.print();打印日志
Log.i();是安卓打印日志用的。

备注:android工程和Java工程还有一定的差异,不能混用他们的库,和函数入口方法。

你可能感兴趣的:(Exception in thread "Thread-0" java.lang.RuntimeException: Stub! at android.util.Log.i(Log.java:...)