2014-04-13 22 views
-4

我的應用程序已停止工作,直到最後的測試。這是我的logcat, 我與它的工作我在工作之前,但現在我沒有工作不幸的是停止工作android應用

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 

這是我的類文件,請幫我ME

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> 

+1

您的logcat告訴您在'com.aswinajay.rubixcubealgorithms.MainActivity.onCreate(MainActivity.java:35)'有一個'NullPointerException'。因此,試着在這裏查看可以爲'null'的原因以及原因。 –

+1

後您的MainActivity代碼 –

+0

請'POST'代碼 –

回答

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

+0

我想「你確保你的activity_main.xml中包含了所有的按鈕」。這就是答案,而他應該檢查這一點。 – mok

+0

@mok我認爲你是對的。 –

+0

謝謝你現在的工作! – user3480258

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); 
+0

不工作!同樣的錯誤,即將 – user3480258

+0

@ user3480258什麼是行號35 – Hariharan

相關問題