0

Whenever I run the app, a run-time error crashes the app. This is my log error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.practiceset2/com.example.android.practiceset2.MainActivity}: android.view.InflateException: Binary XML file line #63: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference

The error only appears if I draw a grey line between two views using a blank dark grey view of 1dp width in my XML file given below:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <android.support.v7.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:orientation="horizontal">


        <android.support.v7.widget.LinearLayoutCompat
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="Team A"
                android:textSize="45sp" />

            <TextView
                android:id="@+id/scoreA_text_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="0"
                android:textSize="45sp" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="score3A"
                android:text="+3 Points" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="score2A"
                android:text="+2 Points" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="freeThrowA"
                android:text="Free Throw" />
        </android.support.v7.widget.LinearLayoutCompat>

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

        <android.support.v7.widget.LinearLayoutCompat
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="Team B"
                android:textSize="45sp" />

            <TextView
                android:id="@+id/scoreB_text_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="0"
                android:textSize="45sp" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="score3B"
                android:text="+3 Points" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="score2B"
                android:text="+2 Points" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="freeThrowB"
                android:text="Free Throw" />
        </android.support.v7.widget.LinearLayoutCompat>
    </android.support.v7.widget.LinearLayoutCompat>

    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="65dp"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:onClick="reset"
        android:text="Reset" />
</LinearLayout>

I cannot understand how drawing this line is causing an error. Is this the correct way to do this? If not, please suggest a way around it.

Mohsin Anees
  • 698
  • 2
  • 9
  • 25

3 Answers3

2

In your XML you used view in small case. you should use View instead of view.

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

Hope it helps:)

Raja
  • 2,775
  • 2
  • 19
  • 31
1

Try to make it <View instead of <view

sasha199568
  • 1,143
  • 1
  • 11
  • 33
0

use this code it's Working well

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

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


        <android.support.v7.widget.LinearLayoutCompat
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="Team A"
                android:textSize="45sp" />

            <TextView
                android:id="@+id/scoreA_text_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="0"
                android:textSize="45sp" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="score3A"
                android:text="+3 Points" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="score2A"
                android:text="+2 Points" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="freeThrowA"
                android:text="Free Throw" />
        </android.support.v7.widget.LinearLayoutCompat>

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="Team B"
                android:textSize="45sp" />

            <TextView
                android:id="@+id/scoreB_text_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:padding="4dp"
                android:text="0"
                android:textSize="45sp" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="score3B"
                android:text="+3 Points" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="score2B"
                android:text="+2 Points" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="8dp"
                android:gravity="center_horizontal"
                android:onClick="freeThrowB"
                android:text="Free Throw" />
        </LinearLayout>
    </LinearLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="65dp"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:onClick="reset"
        android:text="Reset" />
</LinearLayout>
Soni_ji
  • 115
  • 1
  • 12