获取二进制 XML 文件第 141 行:尝试在空对象引用上调用虚拟方法“boolean java.lang.String.equals(java.lang.Object)”
Posted
技术标签:
【中文标题】获取二进制 XML 文件第 141 行:尝试在空对象引用上调用虚拟方法“boolean java.lang.String.equals(java.lang.Object)”【英文标题】:Getting Binary XML file line #141: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference 【发布时间】:2017-10-10 16:19:13 【问题描述】:Logcat
05-11 19:14:52.567 4489-4489/? E/androidRuntime:
FATAL EXCEPTION: main
Process: com.grab.deals.dealcart, PID: 4489
java.lang.RuntimeException: Unable to start activity ComponentInfocom.grab.deals.dealcart/com.grab.deals.dealcart.Full_view.Full_view: android.view.InflateException: Binary XML file line #141: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #141: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.grab.deals.dealcart.Full_view.Full_view.onCreate(Full_view.java:13)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
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:738)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
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.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.grab.deals.dealcart.Full_view.Full_view.onCreate(Full_view.java:13)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
扩展视图.xml
<RelativeLayout 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:id="@+id/activity_full_view"
android:layout_
android:layout_>
<ScrollView
android:layout_
android:layout_>
<LinearLayout
android:layout_
android:layout_
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_
android:layout_
android:layout_margin="5dp">
<LinearLayout
android:layout_
android:layout_
android:orientation="vertical">
<ImageView
android:layout_
android:layout_
android:id="@+id/img"/>
<View
android:layout_
android:layout_/>
<TextView
android:layout_
android:layout_
android:text="Designer shirt"
android:textSize="15dp"
android:layout_marginLeft="10dp"
android:textColor="#000"/>
<LinearLayout
android:layout_
android:layout_
android:orientation="horizontal">
<TextView
android:layout_
android:layout_
android:textSize="12dp"
android:text="Speatial Price"
android:layout_marginLeft="10dp"
android:textColor="#34a853"/>
<TextView
android:layout_
android:layout_marginLeft="5dp"
android:layout_
android:textColor="#000"
android:text="Ends in few hours"
/>
</LinearLayout>
<LinearLayout
android:layout_
android:layout_
android:orientation="horizontal">
<TextView
android:layout_
android:layout_
android:textSize="20dp"
android:text="25,000"
android:layout_marginLeft="10dp"
android:textColor="#000"/>
<TextView
android:layout_
android:layout_marginLeft="10dp"
android:layout_
android:textColor="@color/colorPrimary"
android:text="70%off"
android:textSize="15dp"/>
</LinearLayout>
<LinearLayout
android:layout_
android:layout_
android:orientation="horizontal">
<TextView
android:layout_
android:layout_marginLeft="10dp"
android:layout_
android:textColor="#34a853"
android:text="4.1"/>
<ImageView
android:layout_
android:layout_
app:srcCompat="@drawable/ic_star_border_black_24dp"/>
</LinearLayout>
<View
android:layout_
android:layout_/>
<LinearLayout
android:layout_
android:layout_
android:orientation="horizontal"
android:gravity="center"
android:layout_gravity="center"
android:layout_marginBottom="5dp">
<ImageView
android:layout_
android:layout_
app:srcCompat="@drawable/copy"/>
<TextView
android:layout_
android:layout_
android:textColor="#000"
android:layout_marginLeft="10dp"
android:text="Copy Coupon"
android:textSize="20sp"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_
android:layout_
android:layout_margin="5dp"
>
<LinearLayout
android:layout_
android:layout_
android:orientation="vertical">
<TextView
android:layout_
android:layout_
android:text="Details"
android:layout_margin="20dp"
android:textSize="20sp"
android:textColor="#000"/>
<view
android:layout_
android:layout_/>
<TextView
android:layout_
android:layout_
android:textSize="17sp"
android:textColor="#000"
android:layout_margin="20dp"
android:text="Heighlets \n*shgdfshdflshflsjh\n*a;sjkdfjshgf"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_
android:layout_
android:layout_margin="5dp"
>
<LinearLayout
android:layout_
android:layout_
android:orientation="vertical">
<TextView
android:layout_
android:layout_
android:text="Terms and Conditions"
android:layout_margin="20dp"
android:textSize="20sp"
android:textColor="#000"/>
<view
android:layout_
android:layout_/>
<TextView
android:layout_
android:layout_
android:textSize="17sp"
android:textColor="#000"
android:layout_margin="20dp"
android:text="Heighlets \n*shgdfshdflshflsjh\n*a;sjkdfjshgf"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_
android:layout_
android:layout_margin="5dp"
>
<LinearLayout
android:layout_
android:layout_
android:orientation="vertical">
<TextView
android:layout_
android:layout_
android:text="Ratings & Reviews"
android:layout_margin="20dp"
android:textSize="20sp"
android:textColor="#000"/>
<view
android:layout_
android:layout_/>
<LinearLayout
android:layout_
android:layout_
android:layout_gravity="center"
android:layout_margin="20dp"
android:orientation="vertical">
<LinearLayout
android:layout_
android:layout_
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:layout_
android:layout_
android:text="4.1"
android:layout_marginRight="10dp"
android:textSize="40sp"/>
<ImageView
android:layout_
android:layout_
app:srcCompat="@drawable/ic_star_border_black_24dp"/>
</LinearLayout>
<TextView
android:layout_
android:layout_
android:text="1,500 Reviews"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_
android:layout_
android:orientation="horizontal"
android:background="#fff"
android:layout_alignParentBottom="true"
android:gravity="center">
<Button
android:layout_
android:layout_
android:text="Share"
style="@style/Widget.AppCompat.Button.Borderless.Colored"/>
<Button
android:layout_
android:layout_
android:text="Visit"
android:textColor="#fff"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:background="@color/colorPrimary"/>
</LinearLayout>
</RelativeLayout>
Full_View.java
public class Full_View extends Fragment
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
View rootview = inflater.inflate(R.layout.activity_full_view,container,false);
return rootview;
【问题讨论】:
发布Full_view.java的onCreate()方法 完成@billynomates 它已经在 logcat line# 141 中提到了自己 这能回答你的问题吗? NPE while inflating layout (Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference) 【参考方案1】: <view
android:layout_
android:layout_/>
将view
更改为View
(小写 v
到大写 V
)
【讨论】:
谢谢@billyomates 您好!哈哈,怎么会有很多人像我一样犯这个搞笑的错误?!如果没有这个答案,我不知道如何弄清楚发生了什么疯狂的事情.. 我花了两天时间-_- 这太烦人了。为什么 Android Studio 会对此发出警告? 为我节省了很多时间,谢谢【参考方案2】:请
<view
android:layout_
android:layout_/>
改成
<View
android:layout_
android:layout_/>
【讨论】:
感谢您的回答。【参考方案3】:它是您的 ExtendView.xml 中的视图,视图替换它。
【讨论】:
【参考方案4】:你的view写错了,应该是view
【讨论】:
这如何为现有已接受的答案添加任何内容? 我在这个问题上被困了 3 个小时,只是想确保任何查看这篇文章的人这是正确的答案 最好通过投票正确答案来表达这一点,而不是添加另一个内容基本相同的答案。以上是关于获取二进制 XML 文件第 141 行:尝试在空对象引用上调用虚拟方法“boolean java.lang.String.equals(java.lang.Object)”的主要内容,如果未能解决你的问题,请参考以下文章
Google Map API 问题:android.view.InflateException:二进制 XML 文件第 2 行:二进制 XML 文件第 2 行:膨胀类片段时出错
如何摆脱问题'二进制XML文件第8行:二进制XML文件第8行:使用XYPlot时会膨胀类com.androidplot.xy.XYPlot类]