gpt4 book ai didi

java - getsupportActionBar().setDisplayHomeAsUpEnabled(true).setDisplayHomeAsUpEnabled(true) 抛出 NullPointerException

转载 作者:行者123 更新时间:2023-12-02 04:36:13 25 4
gpt4 key购买 nike

我的应用程序每次崩溃,错误为 java.lang.RuntimeException: Unable to start Activity ComponentInfo{sidssol.com.bit_taxi_b2c/sidssol.com.bit_taxi_b2c.Home}: java.lang.NullPointerException对于 getActionBar().setDisplayHomeAsUpEnabled(true),粘贴了所有必需的代码。任何人都可以检查此代码

public class Home extends ActionBarActivity {
adapter = new NavDrawerListAdapter(getApplicationContext(),
navDrawerItems);


mDrawerList.setAdapter(adapter);

// enabling action bar app icon and behaving it as toggle button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
)
}

样式.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" >
<item name="android:windowTranslucentStatus">true</item>
</style>


<style name="Theme.Test" parent="@style/Theme.AppCompat.Light">

<!-- customize the color palette -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="drawerArrowStyle">@style/Theme.Test.DrawerArrowStyle</item>
</style>

<style name="Theme.Test.DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">@android:color/white</item>
</style>
<style name="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">?android:attr/listDivider</item>
</style>

</resources>

Androidmainfest.xml

  <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".loginForm"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

最佳答案

正如您所看到的,您的主题状态没有操作栏

Theme.AppCompat.Light.NoActionBar

如果您正在使用该主题,则需要使用工具栏或更改主题以使用操作栏

关于java - getsupportActionBar().setDisplayHomeAsUpEnabled(true).setDisplayHomeAsUpEnabled(true) 抛出 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30710716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com