问题描述
view.InflationException:二进制 XML 第 11 行:膨胀类 com.shuhart.stepview.StepView 时出错。更新了依赖项并更新了应用程序。这在更新之前或之后都不起作用。有人可以帮助引起很多挫折,在网上到处搜索解决方案,但似乎没有与此问题相关的任何内容。提前致谢。请参阅下面的代码。
预订活动:
package jod.developer.dyiluckyballsv1;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
import com.shuhart.stepview.StepView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dmax.dialog.SpotsDialog;
import jod.developer.dyiluckyballsv1.Adapter.MyViewPagerAdapter;
import jod.developer.dyiluckyballsv1.Common.Common;
import jod.developer.dyiluckyballsv1.Common.NonswipeviewPager;
import jod.developer.dyiluckyballsv1.Model.Day;
import jod.developer.dyiluckyballsv1.Model.EventBus.ConfirmBookingEvent;
import jod.developer.dyiluckyballsv1.Model.EventBus.DayDoneEvent;
import jod.developer.dyiluckyballsv1.Model.EventBus.displayBallNumberEvent;
import jod.developer.dyiluckyballsv1.Model.EventBus.EnableNextButton;
public class BookingActivity extends AppCompatActivity {
AlertDialog dialog;
CollectionReference dayRef;
@BindView(R.id.step_view)
StepView stepView;
@BindView(R.id.view_pager)
NonswipeviewPager viewPager;
@BindView(R.id.btn_prevIoUs_step)
Button btn_prevIoUs_step;
@BindView(R.id.btn_next_step)
Button btn_next_step;
//Event
@OnClick (R.id.btn_prevIoUs_step)
void prevIoUsstep(){
if(Common.step == 3 || Common.step > 0)
{
Common.step--;
viewPager.setCurrentItem(Common.step);
if(Common.step < 3) //Always enable NEXT when Step < 3
{
btn_next_step.setEnabled(true);
setColorButton();
}
}
}
@OnClick(R.id.btn_next_step)
void nextClick(){
if(Common.step < 3 || Common.step == 0)
{
Common.step++; // Increase
if(Common.step == 1) //After choose club
{
if(Common.currentClub != null)
loadDayByClub(Common.currentClub.getClubId());
}
else if(Common.step == 2) //Pick ball number
{
if(Common.currentDay != null)
loadBallNumberOfDay(Common.currentDay.getDayId());
}
else if(Common.step == 3) //Confirm
{
if(Common.currentBallNumber != -1)
confirmBooking();
}
viewPager.setCurrentItem(Common.step);
}
}
private void confirmBooking() {
EventBus.getDefault().postSticky(new ConfirmBookingEvent(true));
}
private void loadBallNumberOfDay(String dayId) {
EventBus.getDefault().postSticky(new displayBallNumberEvent(true));
}
private void loadDayByClub(String clubId) {
dialog.show();
//Now select all Days from Club
// /County/Louth/Club/enMwWreJM9lTC9IwWplt/Days
if(!TextUtils.isEmpty(Common.county)) {
dayRef = FirebaseFirestore.getInstance()
.collection("AllClub")
.document(Common.county)
.collection("Club")
.document(clubId)
.collection("Day");
dayRef.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
ArrayList<Day> days = new ArrayList<>();
for(QueryDocumentSnapshot daySnapShot:task.getResult())
{
Day day = daySnapShot.toObject(Day.class);
day.setPassword(""); //Remove password in client app
day.setDayId(daySnapShot.getId()); //Get ID of Day
days.add(day);
}
EventBus.getDefault()
.postSticky(new DayDoneEvent(days));
dialog.dismiss();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
dialog.dismiss();
}
});
}
}
//Event Bus Convert
@Subscribe(sticky = true,threadMode = ThreadMode.MAIN)
public void buttonNextReceiver(EnableNextButton event)
{
int step = event.getStep();
if(step == 1)
Common.currentClub = event.getClub();
else if(step == 2)
Common.currentDay = event.getDay();
else if(step == 3)
Common.currentBallNumber = event.getBallNumber();
btn_next_step.setEnabled(true);
setColorButton();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_booking);
ButterKnife.bind(BookingActivity.this);
dialog = new SpotsDialog.Builder().setContext(this).setCancelable(false).build();
setupStepView();
setColorButton();
//View
viewPager.setAdapter(new MyViewPagerAdapter(getSupportFragmentManager()));
viewPager.setoffscreenPageLimit(4); //We have 4 fragments so we need to keep state of this 4 screen page
viewPager.addOnPagechangelistener(new ViewPager.OnPagechangelistener() {
@Override
public void onPageScrolled(int i,float v,int il) {
}
@Override
public void onPageSelected(int i) {
//Show step
stepView.go(i,true);
if(i == 0)
btn_prevIoUs_step.setEnabled(false);
else
btn_prevIoUs_step.setEnabled(true);
//Set disable button next here
btn_next_step.setEnabled(false);
setColorButton();
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
}
private void setColorButton() {
if(btn_next_step.isEnabled())
{
btn_next_step.setBackgroundResource(R.color.colorButton);
}
else
{
btn_next_step.setBackgroundResource(android.R.color.darker_gray);
}
if(btn_prevIoUs_step.isEnabled())
{
btn_prevIoUs_step.setBackgroundResource(R.color.colorButton);
}
else
{
btn_prevIoUs_step.setBackgroundResource(android.R.color.darker_gray);
}
}
private void setupStepView() {
List<String> stepList = new ArrayList<>();
stepList.add("County");
stepList.add("Club");
stepList.add("Number");
stepList.add("Confirm");
stepView.setSteps(stepList);
}
@Override
protected void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
protected void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
}
activity_booking.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:orientation="vertical"
android:background="@color/colorBackground"
tools:context=".BookingActivity">
<com.shuhart.stepview.StepView
android:id="@+id/step_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
app:sv_animationType="Line"
app:sv_stepPadding="12dp"
app:sv_selectedCircleColor="@color/colorButton"
app:sv_selectedStepNumberColor="@android:color/white"
app:sv_selectedTextColor="@color/colorButton"
app:sv_doneCircleColor="@color/colorAccent"
app:sv_donestepLineColor="@color/colorAccent"
app:sv_doneTextColor="@android:color/white"
app:sv_donestepMarkColor="@android:color/white"
app:sv_typeface="@font/bellerose"/>
<jod.developer.dyiluckyballsv1.Common.NonswipeviewPager
android:id="@+id/view_pager"
android:layout_below="@+id/step_view"
android:layout_above="@+id/layout_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="@+id/layout_button"
android:orientation="horizontal"
android:weightSum="2"
android:padding="4dp"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn_prevIoUs_step"
android:text="PrevIoUs"
android:enabled="false"
android:fontFamily="@font/bellerose"
android:layout_centerHorizontal="true"
android:layout_above="@+id/txt_skip"
android:layout_width="0dp"
android:layout_marginRight="4dp"
android:background="@color/colorButton"
android:textColor="@android:color/white"
android:layout_weight="1"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btn_next_step"
android:text="Next"
android:enabled="false"
android:fontFamily="@font/bellerose"
android:layout_centerHorizontal="true"
android:layout_above="@+id/txt_skip"
android:layout_width="0dp"
android:layout_marginLeft="4dp"
android:background="@color/colorButton"
android:textColor="@android:color/white"
android:layout_weight="1"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
build.gradle(:app):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
defaultConfig {
applicationId "jod.developer.dyiluckyballsv1"
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsversion '30.0.2'
}
dependencies {
implementation filetree(dir: "libs",include: ["*.jar"])
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.firebase:firebase-messaging:21.1.0'
implementation 'androidx.appcompat:appcompat:1.3.0-rc01'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'org.jetbrains:annotations:15.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//Add Libraries
//noinspection GradleCompatible
//noinspection GradleCompatible
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.firebase:firebase-firestore:22.1.2'
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
implementation 'com.firebaseui:firebase-ui-auth:5.1.0'
implementation 'com.github.d-max:spots-dialog:1.1@aar'
implementation 'com.ss.bannerslider:bannerslider:2.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.shuhart.stepview:stepview:1.5.1'
implementation 'com.jaredrummler:material-spinner:1.3.1'
implementation 'devs.mulham.horizontalcalendar:horizontalcalendar:1.3.4'
implementation 'com.karumi:dexter:5.0.0'
implementation 'io.paperdb:paperdb:2.6'
implementation 'androidx.room:room-rxjava2:2.4.0-alpha01'
annotationProcessor 'androidx.room:room-compiler:2.4.0-alpha01'
implementation 'com.nex3z:notification-badge:1.0.2'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.9'
implementation 'org.greenrobot:eventbus:3.1.1'
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jod.developer.dyiluckyballsv1">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".HistoryActivity" />
<service android:name=".Service.MyFCMService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity android:name=".CartActivity" />
<activity android:name=".BookingActivity" />
<activity android:name=".HomeActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.google.gms:google-services:4.3.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Logcat:
05-14 18:35:14.174 3510-3510/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: jod.developer.dyiluckyballsv1,PID: 3510
java.lang.RuntimeException: Unable to start activity ComponentInfo{jod.developer.dyiluckyballsv1/jod.developer.dyiluckyballsv1.HomeActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String jod.developer.dyiluckyballsv1.Model.User.getName()' on a null object reference
at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String jod.developer.dyiluckyballsv1.Model.User.getName()' on a null object reference
at jod.developer.dyiluckyballsv1.Fragments.HomeFragment.setUserinformation(HomeFragment.java:504)
at jod.developer.dyiluckyballsv1.Fragments.HomeFragment.onCreateView(HomeFragment.java:402)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.movetoExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentStore.movetoExpectedState(FragmentStore.java:112)
at androidx.fragment.app.FragmentManager.movetoState(FragmentManager.java:1647)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3126)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3070)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:501)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
at android.app.Activity.performStart(Activity.java:6006)
at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2288)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)