0

I've been having trouble with my app stopping/crashing every time I try to switch to a specific activity with a button click. I'm wondering if my manifest file is configured properly, as I'm new to this I'm still in the process of learning to use it.

This is the class activity containing the buttons causing the "App Stop".

package com.example.newdaily;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    Button btn;

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

    public void addClickListener() {
        btn = (Button) findViewById(R.id.start);
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, TasksOrNormal.class));
            }
        });
    }

}

Here's my manifest code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.newdaily">

    <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>
        <activity android:name=".TasksOrNormal" />
        <activity android:name=".Normal"/>
        <activity android:name=".FinalAct" />
        <activity android:name=".hours" />
        <activity android:name=".EnterTasks"
            android:label="@string/title_activity_enter_tasks"
            android:theme="@style/AppTheme.NoActionBar" />



    </application>

</manifest>

stack trace from crash:

 --------- beginning of crash
2020-05-18 17:13:02.178 19125-19125/com.example.newdaily E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.newdaily, PID: 19125
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newdaily/com.example.newdaily.EnterTasks}: java.lang.ClassCastException: com.google.android.material.textfield.TextInputEditText cannot be cast to android.widget.Button
        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.ClassCastException: com.google.android.material.textfield.TextInputEditText cannot be cast to android.widget.Button
        at com.example.newdaily.EnterTasks.onCreate(EnterTasks.java:26)
        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) 
2020-05-18 17:13:02.218 19125-19130/com.example.newdaily I/zygote: Do partial code cache collection, code=27KB, data=53KB
2020-05-18 17:13:02.218 19125-19130/com.example.newdaily I/zygote: After code cache collection, code=27KB, data=53KB
2020-05-18 17:13:02.219 19125-19130/com.example.newdaily I/zygote: Increasing code cache capacity to 256KB
2020-05-18 17:13:02.219 19125-19130/com.example.newdaily I/zygote: JIT allocated 71KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
2020-05-18 17:13:02.219 19125-19130/com.example.newdaily I/zygote: Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
2020-05-18 17:13:02.241 19125-19130/com.example.newdaily I/zygote: Do full code cache collection, code=101KB, data=63KB
2020-05-18 17:13:02.241 19125-19130/com.example.newdaily I/zygote: After code cache collection, code=75KB, data=35KB
thedon
  • 1
  • 1
  • The "App Stop" message means it's crashing. Please [edit] your question to provide the complete [stack trace from the crash](https://stackoverflow.com/a/23353174). – Mike M. May 18 '20 at 01:38
  • In `EnterTasks`'s `onCreate()` method, you're trying to cast a `TextInputLayout` to a `Button`; probably while assigning a `findViewById()` to a variable. Make sure you're using the correct `R.id`s in the `findViewById()` calls, and that you have the types all straight between the layout and the code. – Mike M. May 18 '20 at 21:24
  • Its already answered here https://stackoverflow.com/questions/50150450/textinputedittext-cannot-be-cast-to-textinputlayout – Gunesh Shanbhag May 18 '20 at 21:26

0 Answers0