- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想创建一个应用程序,其中 NavigationView 和 Bottom Navigation 相互配合,但在输出中我得到了“Run”中的下一个字符串
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.mederov.timelord, PID: 24070 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mederov.timelord/com.mederov.timelord.MainActivity}: android.view.InflateException: Binary XML file line #38: Binary XML file line #38: Error inflating class android.support.design.widget.NavigationView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2785) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2863) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1596) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: android.view.InflateException: Binary XML file line #38: Binary XML file line #38: Error inflating class android.support.design.widget.NavigationView Caused by: android.view.InflateException: Binary XML file line #38: Error inflating class android.support.design.widget.NavigationView Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:334) at android.view.LayoutInflater.createView(LayoutInflater.java:647) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at com.mederov.timelord.MainActivity.onCreate(MainActivity.java:24) at android.app.Activity.performCreate(Activity.java:7033) at android.app.Activity.performCreate(Activity.java:7024) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2738) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2863) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1596) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: java.lang.RuntimeException: Unexpected end of document at android.support.v7.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:215) at android.support.v7.view.SupportMenuInflater.inflate(SupportMenuInflater.java:128) at android.support.design.widget.NavigationView.inflateMenu(NavigationView.java:264) at android.support.design.widget.NavigationView.(NavigationView.java:189) at android.support.design.widget.NavigationView.(NavigationView.java:104) at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:334) at android.view.LayoutInflater.createView(LayoutInflater.java:647) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at com.mederov.timelord.MainActivity.onCreate(MainActivity.java:24) at android.app.Activity.performCreate(Activity.java:7033) at android.app.Activity.performCreate(Activity.java:7024) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2738) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2863) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1596) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
.
XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragment_container"
android:layout_above="@id/nav_bar"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
layout="@layout/toolbar_main"
android:id="@+id/toolbar" />
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/nav_bar"
app:menu="@menu/bottom_navigation"
android:background="@color/colorWhite"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/toolbar_menu" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
Java Class
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.nav_bar);
bottomNavigationView.setOnNavigationItemSelectedListener(navListener);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
drawer,
toolbar,
R.string.nav_open_drawer,
R.string.nav_close_drawer);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener((NavigationView.OnNavigationItemSelectedListener) this);
Fragment fragment = new AimsFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.content_frame, fragment);
ft.commit();;
}
private BottomNavigationView.OnNavigationItemSelectedListener navListener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId()){
case R.id.nav_veri:
selectedFragment = new AimsFragment();
break;
case R.id.nav_diary:
selectedFragment = new DiaryFragment();
break;
case R.id.nav_appoint:
selectedFragment = new CalendarFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,selectedFragment).commit();
return true;
}
};
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
Fragment fragment = null;
Intent intent = null;
switch(id){
case R.id.nav_aims:
fragment = new AimsFragment();
break;
case R.id.nav_reminder:
fragment = new ReminderFragment();
break;
case R.id.nav_statics:
fragment = new StaticsFragment();
break;
case R.id.nav_schedule:
fragment = new ScheduleFragment();
break;
case R.id.nav_project:
fragment = new ProjectFragment();
break;
case R.id.nav_settings:
fragment = new SettingsFragment();
break;
case R.id.nav_info:
fragment = new InfoFragment();
break;
default:
fragment = new AimsFragment();
}
if (fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, fragment);
ft.commit();
} else {
startActivity(intent);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
}
Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.mederov.timelord"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
}
Menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_aims"
android:icon="@drawable/idea_aims"
android:title="@string/nav_aims"
android:checked="true" />
<item
android:id="@+id/nav_reminder"
android:icon="@drawable/reminder"
android:title="@string/nav_reminder" />
<item
android:id="@+id/nav_statics"
android:icon="@drawable/statics"
android:title="@string/nav_statics" />
<item
android:id="@+id/nav_schedule"
android:icon="@drawable/scheldule"
android:title="@string/nav_schedule" />
<item
android:id="@+id/nav_project"
android:icon="@drawable/project"
android:title="@string/nav_project" />
</group>
<menu>
<item
android:id="@+id/nav_settings"
android:icon="@drawable/settings"
android:title="@string/nav_settings" />
<item
android:id="@+id/nav_info"
android:icon="@drawable/info"
android:title="@string/nav_info"/>
</menu>
</menu>
Help me please I can't realize how fix this error)
最佳答案
我有同样的错误,我修正了它。问题出在 vector 图标中,如果您尝试在 api 19 上运行它, vector 只能在 api 级别 21+ 上运行 - 他的意愿不适用于您。
关于java - 如何修复 "Error inflating class android.support.design.widget.NavigationView",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54636695/
我有一个 ListView ,每个项目加载一个 fragment ,其中包括另一个 fragment 。第一次充电没问题,但是当我返回到 lisview 并重新加载另一个 fragment (或相同
我浏览了 API 但没能很好地理解。我无法理解这种方法的结果。我是 Android 的新手,需要帮助。 package com.javacodegeeks.android.fragmentstest;
在我的 MenuAdapter 类中尝试膨胀 View 时,我不断收到 InflateException。我将麻烦的代码包围在 try-catch block 中并收到错误消息: 整个项目的链接: h
好吧,事情就是这样,我观看了大量视频并阅读了大量文章,但我找不到解决方案...... 基本上,我的应用程序崩溃是因为我正在膨胀,而且我找不到解决方案。 JAVA: package com.iweto;
我正在研究此链接中的 fragment :http://developer.android.com/guide/components/fragments.html 有一段代码如下: public st
在我的 Android 应用程序中,我正在构建我的第一个自定义适配器。我现在在膨胀 convertView 的那一行遇到了一个空指针。请看下面的代码: private List possibiliti
我有布局,我想膨胀它 喜欢 LinearLayout ll=(LinearLayout)findViewById(R.id.llContainer);
Fragment 中的以下几行引发异常,我无法找到其根本原因。 public View onCreateView(LayoutInflater inflater, ViewGroup containe
我在以下行上遇到强制关闭错误: view = inflater.inflate(R.layout.video_list_item, parent, false); 当将java类设置为 Activit
我正在开发一款 Android 应用,我尝试在该应用中实现社交分享按钮。 我查看了 Android 文档以进行共享 - Sharing simple data并在那里实现代码;然而,应用程序在启动时崩
我们正在尝试构建一个基于 php 的视频共享站点,允许用户上传他们自己的内容。 我们需要将所有这些视频转换为中等质量的 mp4 视频文件,以便最终通过 FlowPlayer 进行流式传输。 我们的代码
在我的应用程序中,我尝试使用 java 的 Inflater/Deflater 类来压缩/解压缩字节数组。这是我最初使用的部分代码: ByteArrayOutputStream outputSt
Deflater 压缩由 0 到 99 字节组成的字节数组(长度为 100)压缩后的字节数组被传递给 Inflater 作为解压缩的输入。解压缩器返回的长度比原始列表缺少 3 个字节。 以下是代码:
我想使用java.util.zip包恢复压缩的中等长度字符串(665个字符),压缩是通过以下代码进行的: public String compress(String s){ Deflater
有什么方法可以覆盖默认的 layoutInflater 以便能够根据我的意愿动态创建布局,同时从数据库中获取 XML 结构的数据? 哈密扎克 最佳答案 您可以使用 LayoutInflater.set
我正在尝试学习 Android,但我不明白 Inflate 的真正作用。我见过不同的示例,在这些示例中,它用于在另一个布局中插入布局,但我不确定在哪里使用它比较好。 任何人都可以提供好的例子吗? 最佳
这个问题在这里已经有了答案: Why does LayoutInflater ignore the layout_width and layout_height layout parameters
我有一个带滑动导航的 android Activity (使用 ViewPager 实现)。 public class UberActivity extends FragmentActivity {
我是 Android 的新手,我试图在 xml 中扩展布局,但我得到了一个 RuntimeException。除了我的 Activity 类和扩展 SurfaceView 的类之外,我几乎删除了所有内
在 Unity documentation他们谈论充气类型,例如在这里: 字段值不能是泛型类型(膨胀类型)的特定特化。 这究竟是什么意思? 最佳答案 Mono's documentation ,Uni
我是一名优秀的程序员,十分优秀!