2012-10-21 115 views
2

我瀏覽了這個網站幾個小時,沒有找到我的問題的解決方案: Eclipse告訴我這個沒有錯誤,但當我按下「是」(誰是誰打開了下一個活動我的 「主屏幕」 的)按鈕的應用程序崩潰, 的清單: 開始活動與按鈕

<uses-sdk 
    android:minSdkVersion="10" 
    android:targetSdkVersion="15" /> 

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".Openscreen" 
     android:label="@string/title_activity_openscreen" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".Q1" 
     android:label="@string/title_activity_q1" > 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".Q2" 
     android:label="@string/title_activity_q2" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
     </intent-filter> 
    </activity> 
</application> 

</manifest> 

這裏是我的Openscreen.java文件:

package com.atf.the.ultimate.onehundred.quiz; 

import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.View; 
import android.widget.Button; 

public class Openscreen extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_openscreen); 

    Button homescreen_yes = (Button) findViewById(R.id.homescreen_yes); 
    homescreen_yes.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v) { 
     Intent homescreen_yes = new Intent(Openscreen.this, Q1.class); 
     startActivity(homescreen_yes); 
     } 
    }); 
    } 

public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.activity_openscreen, menu); 
    return true; 
} 

}

,這裏是我的XML的openscreen(activity_openscreen.xml)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="68dp" 
    android:text="Hello and welcome to the 100 questions quiz. In this quiz you will be  asked a series of quiestions, each with 3 answer possibilities. Select the right one to proceed, if you fail a quiestion you will lose and have to start over again! Remember to save when you exit, progress is not saved automatically!" 
    tools:context=".Openscreen" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:text="Are you ready to start?" 
    tools:context=".Openscreen" /> 

<Button 
    android:id="@+id/homescreen_yes" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/textView2" 
    android:layout_below="@+id/textView2" 
    android:layout_marginTop="78dp" 
    android:text="Yes!" 
    android:onClick= "" /> 

<Button 
    android:id="@+id/homescreen_no" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/homescreen_yes" 
    android:layout_alignBottom="@+id/homescreen_yes" 
    android:layout_alignRight="@+id/textView2" 
    android:text="No!" 
    android:onClick="exit" /> 

</RelativeLayout> 

的logcat:

 10-21 00:25:29.972: INFO/ActivityManager(67): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.atf.the.ultimate.onehundred.quiz/.Openscreen } from pid 139 
10-21 00:25:31.110: INFO/ActivityManager(67): Start proc com.atf.the.ultimate.onehundred.quiz for activity com.atf.the.ultimate.onehundred.quiz/.Openscreen: pid=813 uid=10034 gids={} 
10-21 00:25:34.120: INFO/ActivityManager(67): Displayed com.atf.the.ultimate.onehundred.quiz/.Openscreen: +3s399ms (total +30m34s364ms) 
10-21 00:25:36.670: INFO/ActivityManager(67): Starting: Intent { cmp=com.atf.the.ultimate.onehundred.quiz/.Q1 } from pid 813 
10-21 00:25:37.070: DEBUG/AndroidRuntime(813): Shutting down VM 
10-21 00:25:37.080: WARN/dalvikvm(813): threadid=1: thread exiting with uncaught exception (group=0x40015560) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813): FATAL EXCEPTION: main 
10-21 00:25:37.131: ERROR/AndroidRuntime(813): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.atf.the.ultimate.onehundred.quiz/com.atf.the.ultimate.onehundred.quiz.Q1}: java.lang.NullPointerException 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at android.os.Handler.dispatchMessage(Handler.java:99) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at android.os.Looper.loop(Looper.java:123) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at android.app.ActivityThread.main(ActivityThread.java:3683) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at java.lang.reflect.Method.invokeNative(Native Method) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at java.lang.reflect.Method.invoke(Method.java:507) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at dalvik.system.NativeStart.main(Native Method) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813): Caused by: java.lang.NullPointerException 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at com.atf.the.ultimate.onehundred.quiz.Q1.onCreate(Q1.java:19) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
10-21 00:25:37.131: ERROR/AndroidRuntime(813):  ... 11 more 
10-21 00:25:37.180: WARN/ActivityManager(67): Force finishing activity com.atf.the.ultimate.onehundred.quiz/.Q1 
10-21 00:25:37.283: WARN/ActivityManager(67): Force finishing activity com.atf.the.ultimate.onehundred.quiz/.Openscreen 
10-21 00:25:37.790: WARN/ActivityManager(67): Activity pause timeout for HistoryRecord{40803998 com.atf.the.ultimate.onehundred.quiz/.Q1} 
10-21 00:25:40.120: INFO/Process(813): Sending signal. PID: 813 SIG: 9 
10-21 00:25:40.231: INFO/ActivityManager(67): Process com.atf.the.ultimate.onehundred.quiz (pid 813) has died. 
10-21 00:25:40.240: ERROR/InputDispatcher(67): channel '4075d390 com.atf.the.ultimate.onehundred.quiz/com.atf.the.ultimate.onehundred.quiz.Openscreen (server)' ~ Consumer closed input channel or an error occurred. events=0x8 
10-21 00:25:40.250: ERROR/InputDispatcher(67): channel '4075d390 com.atf.the.ultimate.onehundred.quiz/com.atf.the.ultimate.onehundred.quiz.Openscreen (server)' ~ Channel is unrecoverably broken and will be disposed! 
10-21 00:25:40.510: INFO/WindowManager(67): WIN DEATH: Window{4075d390 com.atf.the.ultimate.onehundred.quiz/com.atf.the.ultimate.onehundred.quiz.Openscreen paused=true} 
10-21 00:25:40.850: WARN/InputManagerService(67): Got RemoteException sending setActive(false) notification to pid 813 uid 10034 
10-21 00:25:49.770: WARN/ActivityManager(67): Activity destroy timeout for HistoryRecord{40811148 com.atf.the.ultimate.onehundred.quiz/.Openscreen} 
10-21 00:25:49.920: WARN/ActivityManager(67): Activity destroy timeout for HistoryRecord{40803998 com.atf.the.ultimate.onehundred.quiz/.Q1} 
10-21 00:25:53.320: DEBUG/SntpClient(67): request time failed: java.net.SocketException:  Address family not supported by protocol 

註釋按鈕沒有工作;但它仍然崩潰

+1

時壓傷,是什麼在THR logcat中說,一個NullPointerException? –

+1

什麼是'Q1.class'?你確定它有效嗎? – onemach

+0

'在com.atf.the.ultimate.onehundred.quiz.Q1.onCreate(Q1.java:19)'表示在'Q1.class'的第19行有一個'NullPointerException'。發佈此課程。 – Nerd

回答

1

從按鈕中刪除,因爲您沒有用該方法調用它們。

編輯: 你的logcat表明,在類Q1

+0

應用程序仍然崩潰,我有評論顯示! – alekthefirst

+0

讓它工作: – alekthefirst

+0

setContentView(R.layout.activity_q1);被錯放在Q1.class文件中,抱歉沒有檢查,並浪費你的時間 – alekthefirst