1

i'm getting java.lang.NullPointerException. And i don't know how to solve it. looking for some help here What i'v tried:

to look here java.lang.RuntimeException: Unable to start activity ComponentInfo But, it didn't help me

to clean and Rebuild project. to Invalidate Cache and Restart in Android studio

and i'v discovered some problems in LayoutInflater.java It cant resolve some imports" sorry cant import images yet this is and image of errors in LayoutInflater.java

My XML file activity_main.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"
    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="wrap_content"
        android:orientation="horizontal"
        android:weightSum="100">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_marginBottom="16dp"
                android:gravity="center"
                android:text="Team A" />

            <TextView
                android:id="@+id/team_a_score"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_marginBottom="24dp"
                android:gravity="center"
                android:textSize="50sp"
                android:text="0" />

            <Button
                android:id="@+id/three_points_button_a"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:onClick="plusThreePointsA"
                android:text="+3 Points" />

            <Button
                android:id="@+id/two_points_button_a"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:onClick="plusTwoPointsA"
                android:text="+2 Points" />

            <Button
                android:id="@+id/free_throw_button_a"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:onClick="plusOnePointA"
                android:text="Free Throw" />
        </LinearLayout>
        <view
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="@android:color/darker_gray"
            />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:orientation="vertical">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_marginBottom="16dp"
                android:gravity="center"
                android:text="Team B" />

            <TextView
                android:id="@+id/team_b_score"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_marginBottom="24dp"
                android:gravity="center"
                android:textSize="50sp"
                android:text="0" />

            <Button
                android:id="@+id/three_points_button_b"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:onClick="plusThreePointsB"
                android:text="+3 Points" />

            <Button
                android:id="@+id/two_points_button_b"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:onClick="plusTwoPointsB"
                android:text="+2 Points" />

            <Button
                android:id="@+id/free_throw_button_b"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:layout_marginLeft="24dp"
                android:layout_marginRight="24dp"
                android:onClick="plusOnePointB"
                android:text="Free Throw" />


        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom|center"
        android:orientation="vertical">

        <Button
            android:id="@+id/reset_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="24dp"
            android:onClick="reset"
            android:text="Reset" />
    </LinearLayout>


</LinearLayout>

My MainActivity.java

package com.example.problems;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    int scoreA = 0;
    int scoreB = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void plusThreePointsA(View view){
        scoreA = scoreA+3;
        displayScoreA(scoreA);
    }

    public void plusTwoPointsA(View view){
        scoreA = scoreA+2;
        displayScoreA(scoreA);
    }

    public void plusOnePointA(View view){
        scoreA = scoreA+1;
        displayScoreA(scoreA);
    }

    public void plusThreePointsB(View view){
        scoreB = scoreB+3;
        displayScoreB(scoreB);
    }

    public void plusTwoPointsB(View view){
        scoreB = scoreB+2;
        displayScoreB(scoreB);
    }

    public void plusOnePointB(View view){
        scoreB = scoreB+1;
        displayScoreB(scoreB);
    }

    public void displayScoreA (int score){
        TextView viewScore = findViewById(R.id.team_a_score);
        viewScore.setText(String.valueOf(score));

    }
    public void displayScoreB (int score){
        TextView viewScore = findViewById(R.id.team_b_score);
        viewScore.setText(String.valueOf(score));

    }

    public void reset (View view){
        scoreA = 0;
        scoreB = 0;

        displayScoreA(scoreA);
        displayScoreB(scoreB);

    }
}

Error that i get

    --------- beginning of crash
05-11 08:14:25.720 4084-4084/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.problems, PID: 4084
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.problems/com.example.problems.MainActivity}: java.lang.NullPointerException: 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:2298)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
        at android.app.ActivityThread.access$800(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        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:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     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:715)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.example.problems.MainActivity.onCreate(MainActivity.java:17)
        at android.app.Activity.performCreate(Activity.java:5933)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
        at android.app.ActivityThread.access$800(ActivityThread.java:144) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5221) 
        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:899) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
05-11 08:19:26.000 4084-4084/com.example.problems I/Process: Sending signal. PID: 4084 SIG: 9
Alexandr
  • 11
  • 1

1 Answers1

1

Use :

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

instead of :

<view
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="@android:color/darker_gray"
            />
  • Oh my god... THX. so much trouble because of so little mistake... – Alexandr May 11 '20 at 13:16
  • Can you plz explain me, you found it just by looking in my xml file, or there is some clues in errors? – Alexandr May 11 '20 at 13:23
  • Actually i tried this code. somehow my android studio mentioned an error in xml file at line no 72 i guess. that's how i got it. Btw i am using android studio 3.5 – Akash Bisht May 11 '20 at 13:32
  • I will try that version. Thx very much! – Alexandr May 11 '20 at 13:39
  • You can find mistake visually by looking at it, You were using `view` Instead of `View`. `View` is an parent for all view components like button, list, textview, radiobutton etc but `view` is not – GeekWithGlasses May 12 '20 at 12:03