gpt4 book ai didi

android - 滑动标签 - NullPointerException - Toolbar.getTitle()

转载 作者:行者123 更新时间:2023-11-30 02:04:18 24 4
gpt4 key购买 nike

我正在尝试在我的应用程序中实现选项卡。问题在于工具栏为空。我正在学习本教程:http://android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html

错误:

java.lang.NullPointerException:尝试在空对象引用上调用虚方法“java.lang.CharSequence android.support.v7.widget.Toolbar.getTitle()”

activity_main.xml

<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">

<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>

<com.android4devs.slidingtab.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"
android:background="@color/colorPrimary"/>

<android.support.v4.view.ViewPager
android:id="@+id/pager"

android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
></android.support.v4.view.ViewPager>

</LinearLayout>

主 Activity .java

toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar); //error

工具栏.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:elevation="2dp"
android:theme="@style/Base.ThemeOverlay.AppCompat.Light" />

最佳答案

显然错误是因为我忘记返回 setContentView(R.layout.activity_main);

关于android - 滑动标签 - NullPointerException - Toolbar.getTitle(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30956325/

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