不幸的是app停止了 - AVD

时间:2014-04-24 15:21:48

标签: android eclipse android-emulator

我的项目中没有错误,但我收到“遗憾的应用已停止”错误。

以下是我的代码:

MainActivity

public class MainActivity extends ActionBarActivity {

AnimationDrawable roseAnimation;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (savedInstanceState == null) 
    {
        getSupportFragmentManager().beginTransaction()
        .add(R.id.container, new PlaceholderFragment()).commit();
    }

    final ImageView roseAnimHolder = (ImageView) findViewById(R.id.imageView1);
    roseAnimHolder.setBackgroundResource(R.drawable.rose_animation);
    roseAnimHolder.post(new Runnable() 
    {
        public void run() 
        {
            roseAnimation = (AnimationDrawable) roseAnimHolder.getBackground();
        }
    } );
}   

public void onWindowFocusedChanged(boolean hasFocus) 
{
    roseAnimation.start();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container,
                false);
        return rootView;
    }
}

}

logcat的:

    04-24 11:08:20.632: D/AndroidRuntime(1309): Shutting down VM
    04-24 11:08:20.632: W/dalvikvm(1309): threadid=1: thread exiting with uncaught exception (group=0xb3aa5ba8)
    04-24 11:08:20.642: E/AndroidRuntime(1309): FATAL EXCEPTION: main
    04-24 11:08:20.642: E/AndroidRuntime(1309): Process: fifth.example.graphicdesign, PID:1309 
    04-24 11:08:20.642: E/AndroidRuntime(1309): java.lang.RuntimeException: Unable to start activity
        ComponentInfo{fifth.example.graphicdesign/fifth.example.graphicdesign.MainActivity}: java.lang.NullPointerException
    04-24 11:08:20.642: E/AndroidRuntime(1309): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at android.app.ActivityThread.access$800(ActivityThread.java:135)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at
android.os.Handler.dispatchMessage(Handler.java:102)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at android.os.Looper.loop(Looper.java:136)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at android.app.ActivityThread.main(ActivityThread.java:5017)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at java.lang.reflect.Method.invokeNative(Native Method)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at        java.lang.reflect.Method.invoke(Method.java:515)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at dalvik.system.NativeStart.main(Native Method)
    04-24 11:08:20.642: E/AndroidRuntime(1309): Caused by: java.lang.NullPointerException
    04-24 11:08:20.642: E/AndroidRuntime(1309): at
fifth.example.graphicdesign.MainActivity.onCreate(MainActivity.java:30)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at android.app.Activity.performCreate(Activity.java:5231)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    04-24 11:08:20.642: E/AndroidRuntime(1309): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
    04-24 11:08:20.642: E/AndroidRuntime(1309): ... 11 more
    04-24 11:13:21.042: I/Process(1309): Sending signal. PID: 1309 SIG: 9

0 个答案:

没有答案