简体   繁体   English

Android模拟器中的“不幸的是(应用程序名称)已停止”

[英]“Unfortunately (app name) has stopped” in Android Emulator

I am developing an android app using eclipse. 我正在使用eclipse开发一个android应用程序。 Every time I run it in the AVD I get the error "Unfortunately Has Stopped". 每次我在AVD中运行它时,都会出现错误“不幸已停止”。 Im trying to transition between the Startup activity and the Main Menu activity using android animation. 我正在尝试使用android动画在Startup活动和Main Menu活动之间进行转换。 Here is part of my java code to support the main activity: 这是支持主要活动的Java代码的一部分:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.start_up);
    startAnimating();
}
private void startAnimating() {
    // TODO Auto-generated method stub
    TextView logo1 = (TextView) findViewById(R.id.title);
    Animation fade1 = AnimationUtils.loadAnimation(this, R.animator.fade_in);
    logo1.startAnimation(fade1);
    TextView logo2 = (TextView) findViewById(R.id.secondTV);
    Animation fade2 = AnimationUtils.loadAnimation(this, R.animator.fade_in2);
    logo2.startAnimation(fade2);

    fade2.setAnimationListener(new AnimationListener(){

        @Override
        public void onAnimationEnd(Animation animation) {
            // TODO Auto-generated method stub
            startActivity(new Intent(Startup.this, SymptomViewer.class));
            Startup.this.finish();

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub

        }

    });


    }
protected void onPause(){
    super.onPause();
    TextView logo1 = (TextView) findViewById(R.id.title);
    logo1.clearAnimation();
    TextView logo2 = (TextView) findViewById(R.id.secondTV);
    logo2.clearAnimation();

}
protected void onResume(){
    super.onResume();
    startAnimating();
}
}

I have been searching in forums all over the internet and I cant seem to solve the this. 我一直在互联网上的论坛中搜索,但似乎无法解决此问题。 However I checked the logcat and I found something to do with Null pointer exception, which is involved when making references. 但是,我检查了logcat,发现与Null指针异常有关,在进行引用时会涉及到该异常。 I have run through my code a number of times and it seems fine. 我已经遍历了我的代码很多次,看起来还不错。 What maybe causing this. 可能是什么原因造成的。

Here is the LogCat 这是LogCat

05-06 18:24:58.925: D/AndroidRuntime(1355): Shutting down VM
05-06 18:24:58.925: W/dalvikvm(1355): threadid=1: thread exiting with uncaught exception (group=0xb2a98ba8)
05-06 18:24:58.965: E/AndroidRuntime(1355): FATAL EXCEPTION: main
05-06 18:24:58.965: E/AndroidRuntime(1355): Process: com.example.ubumitrial1, PID: 1355
05-06 18:24:58.965: E/AndroidRuntime(1355): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ubumitrial1/com.example.ubumitrial1.Startup}: java.lang.NullPointerException
05-06 18:24:58.965: E/AndroidRuntime(1355):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at android.os.Handler.dispatchMessage(Handler.java:102)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at android.os.Looper.loop(Looper.java:136)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at android.app.ActivityThread.main(ActivityThread.java:5017)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at java.lang.reflect.Method.invokeNative(Native Method)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at java.lang.reflect.Method.invoke(Method.java:515)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at dalvik.system.NativeStart.main(Native Method)
05-06 18:24:58.965: E/AndroidRuntime(1355): Caused by: java.lang.NullPointerException
05-06 18:24:58.965: E/AndroidRuntime(1355):     at com.example.ubumitrial1.Startup.startAnimating(Startup.java:27)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at com.example.ubumitrial1.Startup.onCreate(Startup.java:17)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at android.app.Activity.performCreate(Activity.java:5231)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-06 18:24:58.965: E/AndroidRuntime(1355):     ... 11 more
05-06 18:25:02.275: I/Process(1355): Sending signal. PID: 1355 SIG: 9
05-06 18:24:58.965: E/AndroidRuntime(1355): Caused by: java.lang.NullPointerException
05-06 18:24:58.965: E/AndroidRuntime(1355):     at com.example.ubumitrial1.Startup.startAnimating(Startup.java:27)

These log lines show that the NPE happend at line 27. Go to that line (double-click the "at" line in Eclipse jumps to the code) 这些日志行显示NPE发生在第27行。转到该行(双击Eclipse中的“ at”行跳转到代码)

This will likely be a line like: widget.doSomething() . 可能是这样的一行: widget.doSomething() The NPE is thrown because widget is null (a previous initialization via findViewById may have failed, you have to fix the id in the layout [or code]). 由于widgetnull而引发NPE(先前通过findViewById初始化可能失败,您必须在布局[或代码]中固定ID)。

FATAL EXCEPTION: main
05-06 18:24:58.965: E/AndroidRuntime(1355): Process: com.example.ubumitrial1, PID: 1355
05-06 18:24:58.965: E/AndroidRuntime(1355): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ubumitrial1/com.example.ubumitrial1.Startup}: java.lang.NullPointerException
05-06 18:24:58.965: E/AndroidRuntime(1355):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)

As per this error message, I sense that You might not have declared this activity properly in your Manifest file. 根据此错误消息,我认为您可能未在清单文件中正确声明此活动。 Did you define it correctly ? 您定义正确吗? Please double check the declaration 请仔细检查报关单

    Caused by: java.lang.NullPointerException
05-06 18:24:58.965: E/AndroidRuntime(1355):     at com.example.ubumitrial1.Startup.startAnimating(Startup.java:27)
05-06 18:24:58.965: E/AndroidRuntime(1355):     at com.example.ubumitrial1.Startup.onCreate(Startup.java:17)

As per this message you are referring to a component which is not initialized properly. 按照此消息,您所指的是未正确初始化的组件。 Please check you lines 17 and 27. Both of these should help to resolve your problem. 请检查您的第17和27行。这两个都应有助于解决您的问题。

In case if unable to solve the problem, Feel free to post code with Line numbers highlighted and also your manifest file. 如果无法解决问题,请随时发布代码,突出显示行号以及清单文件。

I got solution for ubuntu 14.04 LTS Go to terminal type "android AVD" then wait till emulator start. 我得到了ubuntu 14.04 LTS的解决方案。转到终端类型“ android AVD”,然后等待模拟器启动。 Now go to eclipse run your android project and force project to run throw online emulator(that is still running). 现在转到eclipse运行您的android项目,并强制项目运行throw在线仿真器(仍在运行)。 Hope it works for you. 希望对你有效。 CHeers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM