[英]My app crashes when opening tablayout activity
I followed this tutorial to implement a tab layout to my android application. 我遵循了本教程,为Android应用程序实现了标签布局。 I already have an existing android app that I'm deeloping so I had to adjust the tutorial to it a bit.
我已经有一个正在开发的android应用,所以我不得不对该教程进行一些调整。 I'm pretty sure I did everything exactly as I'm supposed to but everytime I click the button that's supposed to open the tab layout activity, my app crashes.
我很确定自己所做的一切都与预期的完全一样,但是每当我单击应该打开选项卡布局活动的按钮时,我的应用就会崩溃。
Main tabLayout activity: 主要的tabLayout活动:
public class Bifrosttabs extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bifrosttabs);
TabHost tabHost = getTabHost();
//CRAFTING TAB
TabSpec craftTabSpec = tabHost.newTabSpec("Crafting");
craftTabSpec.setIndicator("Crafting", getResources().getDrawable(R.drawable.weaponsmith_logo));
Intent craftIntent = new Intent(this, Bifrost.class);
craftTabSpec.setContent(craftIntent);
//ADDITION INFO TAB
TabSpec infoTabSpec = tabHost.newTabSpec("Info");
infoTabSpec.setIndicator("Info", getResources().getDrawable(R.drawable.craft_info));
Intent infoIntent = new Intent(this, Bifrostinfo.class);
infoTabSpec.setContent(infoIntent);
tabHost.addTab(craftTabSpec);
tabHost.addTab(infoTabSpec);
}
Main tabLayout activity XML file: 主要的tabLayout活动XML文件:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
Button method that opens the tab layout activity: 用于打开选项卡布局活动的Button方法:
public void onClick (View v){
switch (v.getId()){
case R.id.button1:
Intent bifrost = new Intent (MainActivity.this, Bifrosttabs.class);
startActivity(bifrost);
break;
...rest of the code for other buttons
Whole Logcat file: 整个Logcat文件:
07-15 17:57:00.084: E/jdwp(14846): Failed writing handshake bytes: Broken pipe (-1 of 14)
07-15 17:57:06.186: E/AndroidRuntime(14846): FATAL EXCEPTION: main
07-15 17:57:06.186: E/AndroidRuntime(14846): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.matthewstudios.gw2legendary/com.example.gw2legendary.tablayouts.Bifrosttabs}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.matthewstudios.gw2legendary/com.example.gw2legendary.craftingactivities.Bifrost}: java.lang.NullPointerException
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.os.Looper.loop(Looper.java:137)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-15 17:57:06.186: E/AndroidRuntime(14846): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 17:57:06.186: E/AndroidRuntime(14846): at java.lang.reflect.Method.invoke(Method.java:511)
07-15 17:57:06.186: E/AndroidRuntime(14846): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-15 17:57:06.186: E/AndroidRuntime(14846): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-15 17:57:06.186: E/AndroidRuntime(14846): at dalvik.system.NativeStart.main(Native Method)
07-15 17:57:06.186: E/AndroidRuntime(14846): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.matthewstudios.gw2legendary/com.example.gw2legendary.craftingactivities.Bifrost}: java.lang.NullPointerException
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2023)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:749)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.widget.TabHost.setCurrentTab(TabHost.java:413)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.widget.TabHost.addTab(TabHost.java:240)
07-15 17:57:06.186: E/AndroidRuntime(14846): at com.example.gw2legendary.tablayouts.Bifrosttabs.onCreate(Bifrosttabs.java:34)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.Activity.performCreate(Activity.java:5104)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-15 17:57:06.186: E/AndroidRuntime(14846): ... 11 more
07-15 17:57:06.186: E/AndroidRuntime(14846): Caused by: java.lang.NullPointerException
07-15 17:57:06.186: E/AndroidRuntime(14846): at com.example.gw2legendary.craftingactivities.Bifrost.onCreate(Bifrost.java:160)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.Activity.performCreate(Activity.java:5104)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-15 17:57:06.186: E/AndroidRuntime(14846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-15 17:57:06.186: E/AndroidRuntime(14846): ... 21 more
07-15 17:57:14.967: E/fb4a(:<default>):MmsConfig(14952): MmsConfig.loadMmsSettings mms_config.xml missing uaProfUrl setting
I'm pretty sure I gave you all the important code that there is to give. 我很确定我已经给了您所有重要的代码。 If I forgot anything please let me know.
如果我忘记了什么,请告诉我。
Thanks to this user , I figured it out! 感谢这个用户 ,我知道了! There was something wrong with line 160 in my class bifrost.
我的课程Bifrost中的第160行出现了问题。
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
These two lines caused all the trouble! 这两行引起了所有麻烦! I guess you can't enable action bar if you have tab layout.
我想如果您具有标签布局,则无法启用操作栏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.