gpt4 book ai didi

java - 应用程序崩溃(android.view.InflateException)

转载 作者:行者123 更新时间:2023-12-02 04:46:26 26 4
gpt4 key购买 nike

我的应用程序在模拟器上运行时崩溃了相关代码如下:-

public class BookingStep4Fragment extends Fragment {
static BookingStep4Fragment instance;
public static BookingStep4Fragment getInstance() {
if (instance == null)
instance = new BookingStep4Fragment();
return instance;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

simpleDateFormat = new SimpleDateFormat("dd/MM/yy");

localBroadcastManager = LocalBroadcastManager.getInstance(getContext());
localBroadcastManager.registerReceiver(confirmBookingReceiver,new IntentFilter(Common.KEY_CONFIRM_BOOKING));
}

@Override
public void onDestroy() {
localBroadcastManager.unregisterReceiver(confirmBookingReceiver);
super.onDestroy();
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);

View itemView = inflater.inflate(R.layout.fragment_booking_step_four,container,false);
unbinder = ButterKnife.bind(this,itemView);

return itemView;

}

}

我的 Logcat 上显示的错误是

android.view.InflateException: Binary XML file line #87: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:761)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at edmt.dev.androidbarberbooking.Fragments.BookingStep4Fragment.onCreateView(BookingStep4Fragment.java:155)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:146)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1244)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1092)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1622)
at android.view.View.measure(View.java:19734)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:19734)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:19734)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:401)
at android.view.View.measure(View.java:19734)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:19734)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19734)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:687)
at android.view.View.measure(View.java:19734)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2271)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1358)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1607)
2019-06-06 19:25:22.904 3826-3826/edmt.dev.androidbarberbooking E/AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:619)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

一旦我在 xml 文件(布局)中设计与上述代码(booking_step_four)直接链接的 UI,它就会崩溃。我是初学者需要一些帮助。任何有关此问题的帮助将不胜感激。

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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/colorBackground">


<ImageView
android:src="@drawable/logo"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<LinearLayout
android:orientation="vertical"
android:padding="8dp"
android:background="@drawable/rounded_dialog"
android:layout_width="match_parent"
android:layout_height="match_parent">


<TextView
android:text="Thank you for using Apoint"
android:textAllCaps="true"
android:textSize="18sp"
android:fontFamily="@font/opensans_bold"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:text="Booking Information"
android:textAllCaps="true"
android:fontFamily="@font/opensans_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:src="@drawable/ic_event_note_black_244dp"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/txt_booking_time_text"
android:text="10h00 at 06/06.2019"
android:textSize="14sp"
android:layout_marginLeft="4dp"
android:fontFamily="@font/opensans_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>


</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:src="@drawable/ic_account_box_black_24dp"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/txt_booking_barber_text"
android:text="David"
android:textSize="14sp"
android:layout_marginLeft="4dp"
android:fontFamily="@font/opensans_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>


</LinearLayout>

<view
android:layout_marginTop="4dp"
android:background="@android:color/background_dark"
android:layout_width="match_parent"
android:layout_height="1dp"/>

<TextView
android:id="@+id/txt_salon_name"
android:text="@string/salon_1"
android:textAllCaps="true"
android:fontFamily="@font/opensans_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:src="@drawable/ic_web_black_24dp"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/txt_salon_website"
android:text="www.salon1.com"
android:textSize="14sp"
android:layout_marginLeft="4dp"
android:fontFamily="@font/opensans_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>


</LinearLayout>


<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:src="@drawable/ic_phone_black_24dp"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/txt_salon_phone"
android:text="0135-232398"
android:textSize="14sp"
android:layout_marginLeft="4dp"
android:fontFamily="@font/opensans_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>


</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:src="@drawable/ic_access_time_black_24dp"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/txt_salon_open_hours"
android:text="9h00 - 19h00"
android:textSize="14sp"
android:layout_marginLeft="4dp"
android:fontFamily="@font/opensans_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>


</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:src="@drawable/ic_location_on_black_24dp"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/txt_salon_address"
android:text="Address of Salon #1"
android:textSize="14sp"
android:layout_marginLeft="4dp"
android:fontFamily="@font/opensans_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>


</LinearLayout>


<Button
android:id="@+id/btn_confirm"
android:text="BOOK"
android:layout_marginTop="8dp"
android:background="@color/colorButton"
android:textColor="@android:color/white"
android:fontFamily="@font/opensans_bold"
android:layout_centerHorizontal="true"
android:layout_above="@+id/txt_skip"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>


</LinearLayout>

最佳答案

在你的 xml 代码中你写的是 view 而不是 View

 <view
android:layout_marginTop="4dp"
android:background="@android:color/background_dark"
android:layout_width="match_parent"
android:layout_height="1dp"/>

更改为

 <View
android:layout_marginTop="4dp"
android:background="@android:color/background_dark"
android:layout_width="match_parent"
android:layout_height="1dp"/>

如果需要,清理/重建您的代码,然后重新运行您的应用。

关于java - 应用程序崩溃(android.view.InflateException),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56479427/

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