On API15 OK, on API 27 error: cannot find symbol variable, for a button

1759 views java
5

I need some help as I cannot find where the issue is. I am stuck.

It is a simple calculator, it has three buttons to perform calculation, plus one more button to clean. Under API 15 works fine, but under API 27 three of the four calculation buttons give error when try to run the app, but all previous checks are ok.

Any advice please?

Thank you

Martin

XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/fondo"
    tools:context="es.ea1ddo.antenacubica.MainActivity">


    <TextView
        android:id="@+id/textView4"
        android:layout_width="41dp"
        android:layout_height="27dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="70dp"
        android:text="@string/m"
        android:textColor="@android:color/holo_green_light"
        android:textColorLink="@android:color/holo_green_light"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.191"
        app:layout_constraintStart_toEndOf="@+id/lambda"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.199" />

    <TextView
        android:id="@+id/lambda"
        android:layout_width="103dp"
        android:layout_height="33dp"
        android:layout_centerVertical="true"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:ellipsize="start"
        android:gravity="end"
        android:textColor="@android:color/holo_green_light"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.458"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.182" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="41dp"
        android:layout_height="26dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="32dp"
        android:text="@string/mhz"
        android:textColor="@android:color/holo_green_light"
        android:textColorLink="@android:color/holo_green_light"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.126"
        app:layout_constraintStart_toEndOf="@+id/frecuencia"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.126" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/calculadora_de_antenas_c_bicas"
        android:textColor="@android:color/holo_green_light"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.025"
        tools:textColor="@android:color/holo_green_light" />


    <Button
        android:id="@+id/borrar"
        android:layout_width="wrap_content"
        android:layout_height="77dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="8dp"
        android:text="@string/borrar"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.12" />



    <TextView
        android:id="@+id/textView"
        android:layout_width="94dp"
        android:layout_height="28dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:text="@string/lambda"
        android:textColor="@android:color/holo_green_light"
        android:textColorLink="@android:color/holo_green_light"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        

answered question

first, clean/rebuild your project and then perform a Gradle sync (via Tools > Android > Sync Project with Gradle Files)

2 Answers

7

Debug

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: es.ea1ddo.antenacubica, PID: 20150
    java.lang.RuntimeException: Unable to start activity ComponentInfo{es.ea1ddo.antenacubica/es.ea1ddo.antenacubica.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
        at es.ea1ddo.antenacubica.MainActivity.onCreate(MainActivity.java:51)
        at android.app.Activity.performCreate(Activity.java:7009)
        at android.app.Activity.performCreate(Activity.java:7000)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

posted this
6

Can you show the screenshot or the logcat to explain the error which you face?

posted this

Have an answer?

JD

Please login first before posting an answer.