-1
06-25 18:30:30.885: E/AndroidRuntime(26556): FATAL EXCEPTION: main
06-25 18:30:30.885: E/AndroidRuntime(26556): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eeee.ftest/com.eeee.ftest.MainActivity}: java.lang.NullPointerException
06-25 18:30:30.885: E/AndroidRuntime(26556): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
06-25 18:30:30.885: E/AndroidRuntime(26556): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
06-25 18:30:30.885: E/AndroidRuntime(26556): at android.app.ActivityThread.access$700(ActivityThread.java:159)
06-25 18:30:30.885: E/AndroidRuntime(26556): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
06-25 18:30:30.885: E/AndroidRuntime(26556): at android.os.Handler.dispatchMessage(Handler.java:99)
06-25 18:30:30.885: E/AndroidRuntime(26556): at android.os.Looper.loop(Looper.java:176)
06-25 18:30:30.885: E/AndroidRuntime(26556): at android.app.ActivityThread.main(ActivityThread.java:5419)
06-25 18:30:30.885: E/AndroidRuntime(26556): at java.lang.reflect.Method.invokeNative(Native Method)
06-25 18:30:30.885: E/AndroidRuntime(26556): at java.lang.reflect.Method.invoke(Method.java:525)
06-25 18:30:30.885: E/AndroidRuntime(26556): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
06-25 18:30:30.885: E/AndroidRuntime(26556): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
06-25 18:30:30.885: E/AndroidRuntime(26556): at dalvik.system.NativeStart.main(Native Method)
06-25 18:30:30.885: E/AndroidRuntime(26556): Caused by: java.lang.NullPointerException
06-25 18:30:30.885: E/AndroidRuntime(26556): at com.eeee.ftest.MainActivity.onCreate(MainActivity.java:21)
06-25 18:30:30.885: E/AndroidRuntime(26556): at android.app.Activity.performCreate(Activity.java:5372)
06-25 18:30:30.885: E/AndroidRuntime(26556): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
06-25 18:30:30.885: E/AndroidRuntime(26556): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
06-25 18:30:30.885: E/AndroidRuntime(26556): ... 11 more
public class MainActivity extends SherlockFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
ActionBar actionbar = getSupportActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab Frag1 = actionbar.newTab().setText("Fragment 1");
ActionBar.Tab Frag2 = actionbar.newTab().setText("Fragment 2");
ActionBar.Tab Frag3 = actionbar.newTab().setText("Fragment 3");
Fragment Fragment1 = new Fragment_1();
Fragment Fragment2 = new Fragment_2();
Fragment Fragment3 = new Fragment_3();
Frag1.setTabListener(new MyTabsListener(Fragment1));
Frag2.setTabListener(new MyTabsListener(Fragment2));
Frag3.setTabListener(new MyTabsListener(Fragment3));
actionbar.addTab(Frag1);
actionbar.addTab(Frag2);
actionbar.addTab(Frag3);
}
class MyTabsListener implements ActionBar.TabListener{
public Fragment fragment;
public MyTabsListener(Fragment fragment){
this.fragment = fragment;
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
ft.replace(R.id.fragment_container, fragment);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
}
發佈您的線路21號 – CodeWarrior
另一個Android NPE?人們會去了解NPE已經......或者更好,去學習Java。 – m0skit0