Eu sou um iniciante e já no meu primeiro tutorial eu tenho esse erro
Eu fiz todo o processo como está no tutorial em vídeo, e quando tento testá-lo no meu telefone, ele faz a compilação, instala, abre e fecha o aplicativo.
Eu olhei em todos os lugares, pesquisei aqui e não encontrei nada.
Este é meu logcat.
10-27 14:46:05.342 20653-20653/com.example.imperador.idadedecachorro E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.imperador.idadedecachorro, PID: 20653
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.imperador.idadedecachorro/com.example.imperador.idadedecachorro.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
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:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:117)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:149)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:56)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:202)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
at com.example.imperador.idadedecachorro.MainActivity.<init>(MainActivity.java:13)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1606)
at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
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:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
10-27 14:46:08.385 20653-20653/com.example.imperador.idadedecachorro I/Process: Sending signal. PID: 20653 SIG: 9
Meu MainActivity:
package com.example.imperador.idadedecachorro;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private EditText IdadeCachorro = findViewById(R.id.textoIdadeID);
private Button BotaoCalcular = findViewById(R.id.botaoCalcularID);
private TextView Resultado = findViewById(R.id.resultadoID);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BotaoCalcular.setOnClickListener ( new View.OnClickListener ( ) {
@SuppressLint ( "SetTextI18n" )
@Override
public
void onClick ( View v ) {
String TextoDigitado = IdadeCachorro.getText().toString();
if(TextoDigitado.isEmpty()) Resultado.setText("Não digitaste nada babaca");
else {
int IdadeDigitada = Integer.parseInt(TextoDigitado);
int ResultadoFinal = IdadeDigitada * 7;
Resultado.setText(ResultadoFinal + " Anos");
}
}
} );
}
}
Meu Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.imperador.idadedecachorro">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Meu MainActivity, Só tem isso no app
<?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="#cafbab"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="81dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_marginBottom="12dp"
android:layout_marginEnd="144dp"
android:layout_marginLeft="144dp"
android:layout_marginRight="144dp"
android:layout_marginStart="144dp"
android:layout_marginTop="16dp"
android:contentDescription="@string/Cont_Descr_Imagem"
app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.289"
app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/textView2"
android:layout_width="325dp"
android:layout_height="0dp"
android:layout_marginBottom="14dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="128dp"
android:text="@string/Texto_informativo"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/textoIdadeID"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.526"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/textoIdadeID"
android:layout_width="136dp"
android:layout_height="wrap_content"
android:layout_marginBottom="31dp"
android:background="#f3fac7"
android:ems="10"
android:hint="@string/Hint_Texto_editavel"
android:inputType="number"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/botaoCalcularID"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<Button
android:id="@+id/botaoCalcularID"
android:layout_width="213dp"
android:layout_height="wrap_content"
android:layout_marginBottom="47dp"
android:text="@string/Texto_botao_calcular"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/resultadoID"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textoIdadeID" />
<TextView
android:id="@+id/resultadoID"
android:layout_width="174dp"
android:layout_height="0dp"
android:layout_marginBottom="102dp"
android:textColor="@android:color/background_dark"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/botaoCalcularID" />
</android.support.constraint.ConstraintLayout>