不幸停止工作Android应用程序

时间:2014-04-13 14:16:40

标签: java android eclipse

我的应用程序一直停止工作,直到最后一次测试。这是我的Logcat, 在我工作之前我正在使用它,但现在我没有工作

04-13 19:44:49.949: E/AndroidRuntime(12824): FATAL EXCEPTION: main
04-13 19:44:49.949: E/AndroidRuntime(12824): Process: com.aswinajay.rubixcubealgorithms, PID: 12824
04-13 19:44:49.949: E/AndroidRuntime(12824): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aswinajay.rubixcubealgorithms/com.aswinajay.rubixcubealgorithms.MainActivity}: java.lang.NullPointerException
04-13 19:44:49.949: E/AndroidRuntime(12824):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at android.os.Handler.dispatchMessage(Handler.java:102)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at android.os.Looper.loop(Looper.java:136)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at android.app.ActivityThread.main(ActivityThread.java:5017)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at java.lang.reflect.Method.invokeNative(Native Method)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at java.lang.reflect.Method.invoke(Method.java:515)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at dalvik.system.NativeStart.main(Native Method)
04-13 19:44:49.949: E/AndroidRuntime(12824): Caused by: java.lang.NullPointerException
04-13 19:44:49.949: E/AndroidRuntime(12824):    at com.aswinajay.rubixcubealgorithms.MainActivity.onCreate(MainActivity.java:35)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at android.app.Activity.performCreate(Activity.java:5231)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-13 19:44:49.949: E/AndroidRuntime(12824):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
04-13 19:44:49.949: E/AndroidRuntime(12824):    ... 11 more

这是我的班级档案,请帮帮我

  package com.aswinajay.rubixcubealgorithms;


  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.*;

  public class MainActivity extends Activity implements OnClickListener {

  Button new_game_button;
  Button continue_button;
  Button about_button;
  Button exit_button;
  Button Notation_button;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    View continue_Button = findViewById(R.id.continue_button);
    continue_Button.setOnClickListener(this);
    View new_game_Button = findViewById(R.id.new_game_button);
    new_game_Button.setOnClickListener(this);
    View about_Button = findViewById(R.id.about_button);
    about_Button.setOnClickListener(this);
    View exit_Button = findViewById(R.id.exit_button);
    exit_Button.setOnClickListener(this);
    View Notation_button = findViewById(R.id.Notation_button);
    Notation_button.setOnClickListener(this);

}


@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){

    case R.id.new_game_button:
    Intent intent = new Intent(MainActivity.this,PLL.class);
    startActivity(intent);
    break;

    case R.id.continue_button:
        Intent intent1 = new Intent(MainActivity.this,F2L.class);
        startActivity(intent1);
        break;

    case R.id.about_button:
        Intent intent4 = new Intent(MainActivity.this,OLL.class);
        startActivity(intent4);
        break;

    case R.id.exit_button:
        Intent intent3 = new Intent(MainActivity.this,About.class);
        startActivity(intent3);
        break;
    case R.id.Notation_button:
        Intent intent5 = new Intent(MainActivity.this,Notation.class);
        startActivity(intent5);
        break;  
    }}
        @Override
        public void onBackPressed() {
            {
            super.onBackPressed();
            this.finish();
            Intent intent = new Intent (this,MainActivity.class);
            startActivity(intent);
            finish();

            super.onBackPressed();
        }







    }











  }

但是代码是正确的我认为如此! 这是我的清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aswinajay.rubixcubealgorithms"
android:versionCode="1"
android:versionName="1.0" >

     <supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />

  <uses-sdk
   android:minSdkVersion="11"
    android:targetSdkVersion="19" />


    <application
       android:allowBackup="true"
        android:icon="@drawable/ic_launcher"

    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity           
        android:name="com.aswinajay.rubixcubealgorithms.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
<activity
        android:name="About"
        android:label="@string/title_activity_about_main" 
        android:screenOrientation="landscape"
        android:theme="@android:style/Theme.Dialog">
    <intent-filter>
        <action android:name="com.example.rubikscubealgorithms.About"></action>
          <category android:name="android.intent.category.DEFAULT" >
          </category>
        </intent-filter>
        </activity>
        <activity 
            android:name="F2L"
            android:label="@string/title_activity_f2l_main"
            android:screenOrientation="landscape">
            <intent-filter>
        <action android:name="com.example.rubikscubealgorithms.F2L"></action>
 <category android:name="android.intent.category.DEFAULT" >
          </category>
        </intent-filter>
        </activity>
           <activity 
            android:name="OLL"
            android:label="@string/title_activity_oll_main"
            android:screenOrientation="landscape">
            <intent-filter>
        <action android:name="com.example.rubikscubealgorithms.OLL"></action>
 <category android:name="android.intent.category.DEFAULT" >
          </category>
        </intent-filter>
        </activity>
        <activity 
            android:name="PLL"
            android:label="@string/title_activity_pll_main"
            android:screenOrientation="landscape">
            <intent-filter>
        <action android:name="com.example.rubikscubealgorithms.PLL"></action>
          <category android:name="android.intent.category.DEFAULT" >
          </category>
        </intent-filter>

        </activity>
        <activity 
            android:name="Basepll"
            android:screenOrientation="landscape">
            <intent-filter>
        <action android:name="com.example.rubikscubealgorithms.Basepll"></action>
          <category android:name="android.intent.category.DEFAULT" >
          </category>
        </intent-filter>

        </activity>
         <activity 
            android:name="Baseoll"
            android:screenOrientation="landscape">
            <intent-filter>
        <action android:name="com.example.rubikscubealgorithms.Baseoll"></action>
          <category android:name="android.intent.category.DEFAULT" >
          </category>
        </intent-filter>

        </activity>
         <activity 
            android:name="Basef2l"
            android:screenOrientation="landscape">
            <intent-filter>
        <action android:name="com.example.rubikscubealgorithms.Basef2l"></action>
          <category android:name="android.intent.category.DEFAULT" >
          </category>
        </intent-filter>

        </activity>
        <activity 
            android:name="Notation"
            android:screenOrientation="landscape">
            <intent-filter>
        <action android:name="com.example.rubikscubealgorithms.Notation"></action>
          <category android:name="android.intent.category.DEFAULT" >
          </category>
        </intent-filter>

        </activity>








</application>

2 个答案:

答案 0 :(得分:1)

试试这个..

以下更改

View continue_Button = findViewById(R.id.continue_button);
continue_Button.setOnClickListener(this);
View new_game_Button = findViewById(R.id.new_game_button);
new_game_Button.setOnClickListener(this);
View about_Button = findViewById(R.id.about_button);
about_Button.setOnClickListener(this);
View exit_Button = findViewById(R.id.exit_button);
exit_Button.setOnClickListener(this);
View Notation_button = findViewById(R.id.Notation_button);
Notation_button.setOnClickListener(this);

作为

continue_Button = (Button) findViewById(R.id.continue_button);
continue_Button.setOnClickListener(this);
new_game_Button = (Button) findViewById(R.id.new_game_button);
new_game_Button.setOnClickListener(this);
about_Button = (Button) findViewById(R.id.about_button);
about_Button.setOnClickListener(this);
exit_Button = (Button) findViewById(R.id.exit_button);
exit_Button.setOnClickListener(this);
Notation_button = (Button) findViewById(R.id.Notation_button);
Notation_button.setOnClickListener(this);

答案 1 :(得分:1)

你应该改变这个

View continue_Button = findViewById(R.id.continue_button);
continue_Button.setOnClickListener(this);
View new_game_Button = findViewById(R.id.new_game_button);
new_game_Button.setOnClickListener(this);
View about_Button = findViewById(R.id.about_button);
about_Button.setOnClickListener(this);
View exit_Button = findViewById(R.id.exit_button);
exit_Button.setOnClickListener(this);
View Notation_button = findViewById(R.id.Notation_button);

使用

continue_Button = (Button) findViewById(R.id.continue_button);
continue_Button.setOnClickListener(this);

new_game_Button = (Button) findViewById(R.id.new_game_button);
new_game_Button.setOnClickListener(this);

about_Button = (Button) findViewById(R.id.about_button);
about_Button.setOnClickListener(this);

exit_Button = (Button) findViewById(R.id.exit_button);
exit_Button.setOnClickListener(this);

Notation_button = (Button) findViewById(R.id.Notation_button);
Notation_button.setOnClickListener(this);

您必须投放所有Button。并确保您的activity_main.xml包含所有Buttons