question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash when using simple view in layout

See original GitHub issue

Hi, using simple view in my layout i have a crash when i inflating layout. Can you fix this bug?

Thanks, Matteo Sist

Stacktrace: 09-24 11:40:48.927 20785-20785/it.example.app E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: it.example.app, PID: 20785 android.view.InflateException: Binary XML file line #21: 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 uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at it.example.app.fragments.PicturePreviewFragment.onCreateView(PicturePreviewFragment.java:77) at android.app.Fragment.performCreateView(Fragment.java:2220) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148) at android.app.BackStackRecord.run(BackStackRecord.java:793) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535) at android.app.FragmentManagerImpl$1.run(FragmentManager.java:482) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) 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.inflate(LayoutInflater.java:515)             at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)             at android.view.LayoutInflater.inflate(LayoutInflater.java:423)             at it.example.app.fragments.PicturePreviewFragment.onCreateView(PicturePreviewFragment.java:77)             at android.app.Fragment.performCreateView(Fragment.java:2220)             at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)             at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)             at android.app.BackStackRecord.run(BackStackRecord.java:793)             at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)             at android.app.FragmentManagerImpl$1.run(FragmentManager.java:482)             at android.os.Handler.handleCallback(Handler.java:739)             at android.os.Handler.dispatchMessage(Handler.java:95)             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)

Code:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_picture_preview, container, false);
    return view;
}

Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/lc_picturePreview"
    android:layout_above="@+id/lc_pictureNavigationBar" />

<LinearLayout
    android:id="@+id/lc_pictureNavigationBar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:layout_alignParentBottom="true"
    android:gravity="center"
    android:orientation="horizontal">

    <!--view cause of crash-->
    <view
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2" />

    <TextView
        android:id="@+id/lc_pictureDelete"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="right"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:textColor="@color/White"
        android:textSize="30sp" />

</LinearLayout>

</RelativeLayout>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
d-rahulcommented, Jan 22, 2018

I encountered this same issue in Activity also when I used view instead of View tag. But found a solution from https://readyandroid.wordpress.com/android-view-inflateexception-binary-xml-file-line-0-attempt-to-invoke-virtual-method-boolean-java-lang-string-equalsjava-lang-object-on-a-null-object-reference-android/ You can found many more Android tricks and solutions from here: https://readyandroid.wordpress.com/

1reaction
chrisjenxcommented, Sep 24, 2015

@matteo-adsolutions nothing to do with Calligraphy, you can’t just inflate a view like that. I use Space and View all the time in similar situations. If you remove Calligraphy you will see the same crash.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android xml, crash of the custom view in a layout
You are trying to build the view from layout xml passing parameters,but you don't have any constructor that can receive them.
Read more >
Layout view crashing ArcMap? - arcgis desktop
I'm using ArcMap 10.3.1 from a basic desktop concurrent use license. The problem I'm experiencing occurs when I load an existing mxd ...
Read more >
Layout crashing Vector Rendering - SketchUp Community
Hi All, I'm having problems rendering a file in layout from raster to vector. I've gone through some of the trouble shooting in...
Read more >
Crash with List using Observable Object - Apple Developer
Hello,. I'm using swiftUI to render my interface, the goal is to made a simple tableView. I'm using List, passing a param that...
Read more >
Auto Layout Crashes on iOS - Embrace Blog and Events
Without defining constraints, developers can also use stack views for simple layouts that follow inherent object sizes and attributes such ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found