android: 采用tablayout+viewpager+fragment实现选项卡出现问题

tang280 2018-06-20 05:00:49
我们采用android sdk 23版本,相关的android.support.design.jar 23.1.0也导入到开发环境中
//如下为MainActivity.java
package com.example.tt;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity {//

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
//如下为activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.tt.MainActivity">

<android.support.design.widget.TabLayout
android:id="@+id/tab_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF3232"
/>

<android.support.v4.view.ViewPager
android:id="@+id/vp_pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

//如下是主要出错信息
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tt/com.example.tt.MainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.design.widget.TabLayout
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.R$attr" on path: DexPathList[[zip file "/data/app/com.example.tt-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.tt-1/lib/arm, /vendor/lib, /system/lib]]
...全文
990 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
pw575895167 2018-09-07
  • 打赏
  • 举报
回复
design jar包是不是没有导入啊
jklwan 2018-09-07
  • 打赏
  • 举报
回复
designer需要引入aar;
「已注销」 2018-08-29
  • 打赏
  • 举报
回复
1.你的运行的真机或者模拟器的android版本是多少,自己去官网查询适配api
2.异常:解析XML文件中的控件对应的类,在资源中没有找到,所有也有可能是你的sdk下载缺失,检查TabLayout在sdk中Sdk\extras\android\m2repository\com\android\support下是否存在,如果没有,自己重新删除破碎的sdk库并下载。
地球太平洋 2018-06-21
  • 打赏
  • 举报
回复
运行环境的android版本是多少?api 23要android 6.0以上才支持。
键盘舞者113 2018-06-20
  • 打赏
  • 举报
回复
ReBuild Project
键盘舞者113 2018-06-20
  • 打赏
  • 举报
回复
ReBuild Project

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧