今天是我第一天用java。我無法弄清楚這個錯誤的原因。無法實例化活動ComponentInfo {com.example.ragefacefolks/com.example.ragefacefolks.MainActivity}:java.lang.NullPointerException
MainActivity.java是這樣的下面
package com.example.ragefacefolks;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.Button;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Button bMain = (Button) findViewById(R.id.button1);
@Override
public void registerForContextMenu(View view) {
// TODO Auto-generated method stub
super.registerForContextMenu(bMain);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
}
不會很難爲你們知道它的說理。需要一點幫助。 日誌貓顯示這些結果
09-27 07:59:24.677: D/AndroidRuntime(555): Shutting down VM
09-27 07:59:24.677: W/dalvikvm(555): threadid=1: thread exiting with uncaught exception (group=0x40015560)
09-27 07:59:24.707: E/AndroidRuntime(555): FATAL EXCEPTION: main
09-27 07:59:24.707: E/AndroidRuntime(555): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.ragefacefolks/com.example.ragefacefolks.MainActivity}: java.lang.NullPointerException
09-27 07:59:24.707: E/AndroidRuntime(555): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
09-27 07:59:24.707: E/AndroidRuntime(555): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-27 07:59:24.707: E/AndroidRuntime(555): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-27 07:59:24.707: E/AndroidRuntime(555): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-27 07:59:24.707: E/AndroidRuntime(555): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 07:59:24.707: E/AndroidRuntime(555): at android.os.Looper.loop(Looper.java:123)
09-27 07:59:24.707: E/AndroidRuntime(555): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-27 07:59:24.707: E/AndroidRuntime(555): at java.lang.reflect.Method.invokeNative(Native Method)
你打我8秒! – Szymon
Thankyou,Raghunadan。我知道這是一個新手問題。 :) –
@ArsalanShah歡迎您。如果它有助於標記答案爲 – Raghunandan