我有一个似乎无法解决的问题,因为它似乎只发生在API 28(Android 9)上。每次我在设备上登录我的应用程序时,都会收到此错误,而且我不知道为什么或如何修复它,因为它似乎仅在此API上发生。我发现堆栈跟踪很难遵循并且不确定如何找到问题的根源。
我将发布堆栈跟踪,但是我不确定要包括哪些其他文件,因此,如果您认为知道问题可能出在哪里,请询问,我将发布您需要的相关文件。
谢谢!
java.lang.RuntimeException: Unable to start activity ComponentInfo{grouppay.dylan.com.grouppay/grouppay.dylan.com.activities.Home}: android.view.InflateException: Binary XML file line #46: Binary XML file line #46: Error inflating class com.google.android.material.navigation.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3108)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3251)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7045)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Caused by: android.view.InflateException: Binary XML file line #46: Binary XML file line #46: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: android.view.InflateException: Binary XML file line #46: Error inflating class com.google.android.material.navigation.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
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.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:543)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
at grouppay.dylan.com.activities.Home.onCreate(Home.java:63)
at android.app.Activity.performCreate(Activity.java:7327)
at android.app.Activity.performCreate(Activity.java:7318)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3088)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3251)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7045)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Caused by: android.view.InflateException: Binary XML file line #34: Binary XML file line #34: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #34: Error inflating class TextView
Caused by: java.lang.StringIndexOutOfBoundsException: length=0; index=0
at java.lang.String.charAt(Native Method)
2019-05-10 16:08:04.130 13315-13315/grouppay.dylan.com.grouppay E/AndroidRuntime: at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:107)
at android.content.res.TypedArray.getInt(TypedArray.java:383)
at android.widget.TextView.readTextAppearance(TextView.java:3917)
at android.widget.TextView.<init>(TextView.java:1258)
at android.widget.TextView.<init>(TextView.java:1112)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:98)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:94)
at androidx.appcompat.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:182)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1365)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1415)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
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.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.google.android.material.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:215)
at com.google.android.material.navigation.NavigationView.inflateHeaderView(NavigationView.java:285)
at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:197)
at com.google.android.material.navigation.NavigationView.<init>(NavigationView.java:104)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
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.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:543)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
at grouppay.dylan.com.activities.Home.onCreate(Home.java:63)
at android.app.Activity.performCreate(Activity.java:7327)
at android.app.Activity.performCreate(Activity.java:7318)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3088)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3251)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7045)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
带有所有相关NavDrawer代码的家庭活动:
public ActiveAccountsRVAdapter adapter;
List<GroupAccount> groupAccounts = new ArrayList<>();
private RecyclerView accountsRecyclerView;
private RecyclerView.LayoutManager accountsRecyclerViewLayoutManager;
private TextView noAccountsTextView, navName, navEmail;
private DrawerLayout drawerLayout;
private ActionBarDrawerToggle actionBarDrawerToggle;
private NavigationView navigationView;
private SwipeRefreshLayout pullToRefresh;
private String userId, userName, userEmail, profileImgUrl;
private int numberOfActiveGroups;
private GroupAccountAPI apiInterface;
private ImageView navDrawerProfileImage, noAccountsImgView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
userId = getIntent().getStringExtra("userId");
userName = getIntent().getStringExtra("name");
userEmail = getIntent().getStringExtra("email");
profileImgUrl = getIntent().getStringExtra("profileImgUrl");
setUpFAB();
setUpAccountPreviewRecyclerView();
//noAccountsTextView = (TextView)
findViewById(R.id.noAccountPreviewsTextView);
pullToRefresh = findViewById(R.id.homePullToRefresh);
pullToRefresh.setColorSchemeResources(R.color.colorAccent);
pullToRefresh.setOnRefreshListener(new
SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
setUpAssociatedAccountsCall(userId);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
pullToRefresh.setRefreshing(false);
}
},4000);
}
});
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
R.string.nav_drawer_open, R.string.nav_drawer_close);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
setUpActionBar();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setUpNavDrawer();
}
private void setUpNavDrawer() {
navigationView = (NavigationView) findViewById(R.id.navView);
View headerView = navigationView.getHeaderView(0);
navName = (TextView) headerView.findViewById(R.id.navName);
navEmail = (TextView) headerView.findViewById(R.id.navEmail);
navName.setText(userName);
navEmail.setText(userEmail);
navDrawerProfileImage = (ImageView)headerView.findViewById(R.id.navDrawerProfileImage);
if(profileImgUrl != null) {
Glide.with(navDrawerProfileImage.getContext())
.load(profileImgUrl)
.into(navDrawerProfileImage);
} else {
navDrawerProfileImage.setImageDrawable(getResources().getDrawable(R.drawable.no_profile_photo));
}
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_profile:
Intent profileIntent = new Intent(Home.this, Profile.class);
profileIntent.putExtra("userId", userId);
startActivityForResult(profileIntent, 100);
break;
case R.id.nav_cards:
Intent intentPaymentMethods = new Intent(Home.this, PaymentMethods.class);
intentPaymentMethods.putExtra("userIdStr", userId);
startActivityForResult(intentPaymentMethods, 120);
break;
case R.id.nav_transactions:
Intent intentTransactions = new Intent(Home.this, AllTransactions.class);
intentTransactions.putExtra("userIdStr", userId);
intentTransactions.putExtra("numberOfGroups", String.valueOf(groupAccounts.size()));
startActivity(intentTransactions);
break;
case R.id.nav_logout:
Intent intentLogin = new Intent(Home.this, Login.class);
startActivity(intentLogin);
break;
default:
return true;
}
return true;
}
});
}
原始XML容器:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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"
android:clickable="true"
android:focusableInTouchMode="true">
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activities.MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/homeToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/whiteText"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/activity_home_main_content" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabAddAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:backgroundTint="@color/whiteText"
app:backgroundTint="@color/homeFAB"
app:borderWidth="1dp"
app:srcCompat="@drawable/plus_icon_blue" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/home_nav_menu"
android:layout_gravity="start"
app:headerLayout="@layout/activity_home_nav_drawer_header"
android:id="@+id/navView">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>