0

我的代码有错误。请帮忙

代码

public void toCallAsynchronous() {
    Log.d(Tag, "проверка toCallAsynchronous");
    final Handler handler = new Handler();
    Timer timer = new Timer();
    TimerTask doAsynchronousTask = new TimerTask() {

        @Override
        public void run() {

            handler.post(new Runnable() {
                public void run() {
                    try {
                                    // TODO: handle exception
                                    //AutoPretraga zadatak = new AutoPretraga();
                                    //zadatak.execute();
                                        startService(
                                         new Intent(ctx, ServiceUpdate.class));
                                              Log.d(Tag, "ГУГЛ вперед!!!!!!!!");
                                              //googleConnect();



                    } catch (Exception e) {
                        Log.d(Tag, e.getMessage());
                    }
                }
            });

        }
    };
    timer.schedule(doAsynchronousTask, 0, 60000); // execute in every 2 second
}

日志

05-30 12:12:04.984: E/AndroidRuntime(9545): FATAL EXCEPTION: main
05-30 12:12:04.984: E/AndroidRuntime(9545): java.lang.NullPointerException: println needs a message
05-30 12:12:04.984: E/AndroidRuntime(9545):     at android.util.Log.println_native(Native Method)
05-30 12:12:04.984: E/AndroidRuntime(9545):     at android.util.Log.d(Log.java:154)
05-30 12:12:04.984: E/AndroidRuntime(9545):     at com.example.ok1.CopyOfMainActivity$1$1.run(CopyOfMainActivity.java:514)
05-30 12:12:04.984: E/AndroidRuntime(9545):     at android.os.Handler.handleCallback(Handler.java:587)
05-30 12:12:04.984: E/AndroidRuntime(9545):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-30 12:12:04.984: E/AndroidRuntime(9545):     at android.os.Looper.loop(Looper.java:130)
05-30 12:12:04.984: E/AndroidRuntime(9545):     at android.app.ActivityThread.main(ActivityThread.java:3687)
05-30 12:12:04.984: E/AndroidRuntime(9545):     at java.lang.reflect.Method.invokeNative(Native Method)
05-30 12:12:04.984: E/AndroidRuntime(9545):     at java.lang.reflect.Method.invoke(Method.java:507)
05-30 12:12:04.984: E/AndroidRuntime(9545):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-30 12:12:04.984: E/AndroidRuntime(9545):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-30 12:12:04.984: E/AndroidRuntime(9545):     at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

0

问题位于文件 CopyOfMainActivity.java 的第 514 行,调用 Log.d 方法。我猜是这条线

Log.d(Tag, "ГУГЛ вперед!!!!!!!!");

但是当我查看这段代码时,我认为由于“Tag”,所有对 Log 方法的调用都会出现问题。

你有一个字符串类型的变量标签吗?如果是,那么 Android 可能对这些非拉丁字符有问题,但我对此表示怀疑。

尝试编辑所有您记录的呼叫,例如:

Log.d("myservice", "ГУГЛ вперед!!!!!!!!");
于 2013-05-30T09:16:54.250 回答