My app 在Android Studio中一直崩溃..运行不起来

文章标签: android,android-studio
2015-1-4 9:16:21     人阅读    

我正在开发一个android 定时器的app,开发工具使用的  Android Studio ,但是每次我运行的时候它都崩溃,运行不起来,希望有人帮忙看下,我想运行起来当做我的圣诞礼物
Here is my code:

public class TimerActivity extends ActionBarActivity {
    Button btnStart = (Button) findViewById(R.id.btnStart);
    TextView txtTimer = (TextView) findViewById(R.id.textViewTime);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_timer);
       // btnStart.setBackgroundColor(0x57C173);

        final CountDownTimer timer = new CountDownTimer(60000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                long secondsRemaining = millisUntilFinished / 60;
                long minutesRemaining = secondsRemaining / 60;
                secondsRemaining = secondsRemaining % 60;

                txtTimer.setText(minutesRemaining + ":" + secondsRemaining);
            }

            @Override
            public void onFinish() {
                txtTimer.setText("You are Awesome!");
            }
        };

        btnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                timer.start();
                btnStart.setText("Cancel");

                btnStart.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        timer.cancel();
                        btnStart.setText("Start");
                        txtTimer.setText("1:00");
                    }
                });
            }
        });
    }
}

 Logcat 报错信息如下

12-24 14:48:01.324  16878-16878/com.mintemovement.minutemovement W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x416a9e30)
1
12-24 14:48:01.334  16878-16878/com.mintemovement.minutemovement E/AndroidRuntime﹕ FATAL EXCEPTION: main
 
    Process: com.mintemovement.minutemovement, PID: 16878
 
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mintemovement.minutemovement/com.mintemovement.minutemovement.TimerActivity}: java.lang.NullPointerException
 
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2357)
 
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
 
            at android.app.ActivityThread.access$800(ActivityThread.java:153)
 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
 
            at android.os.Handler.dispatchMessage(Handler.java:102)
 
            at android.os.Looper.loop(Looper.java:157)
 
            at android.app.ActivityThread.main(ActivityThread.java:5633)
 
            at java.lang.reflect.Method.invokeNative(Native Method)
 
            at java.lang.reflect.Method.invoke(Method.java:515)
 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896)
 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)
 
            at dalvik.system.NativeStart.main(Native Method)
 
     Caused by: java.lang.NullPointerException
 
            at android.app.Activity.findViewById(Activity.java:1952)
 
            at com.mintemovement.minutemovement.TimerActivity.<init>(TimerActivity.java:12)
 
            at java.lang.Class.newInstanceImpl(Native Method)
 
            at java.lang.Class.newInstance(Class.java:1208)
 
            at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
 
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2348)
�
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
�
            at android.app.ActivityThread.access$800(ActivityThread.java:153)
�
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
�
            at android.os.Handler.dispatchMessage(Handler.java:102)
�
            at android.os.Looper.loop(Looper.java:157)
�
            at android.app.ActivityThread.main(ActivityThread.java:5633)
�
            at java.lang.reflect.Method.invokeNative(Native Method)
�
            at java.lang.reflect.Method.invoke(Method.java:515)
�
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896)
�
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)
�
            at dalvik.system.NativeStart.main(Native Method)


原文地址:http://www.itmmd.com/201501/433.html
该文章由 萌萌的IT人 整理发布,转载须标明出处。

android navidgation drawer 在导航抽屉中如何改变List选中项的颜色?   上一篇
下一篇  Android NDK找不到本地函数
精彩回复
我要追加问题,请求站长解决!
姓名:       

《程序员app》专门为程序员量身定做!