Surbhi Bansal
Surbhi Bansal

Reputation: 1

mobile app bug report showing for self made app

I am new in android learning Using this My app name is Threads.In Xml there is one Textview and button. When I click on button there will app shows "Threads has stopped" .

In this app I'm learning about how to us threads while developing app.

    package com.codewithjarvis.threads;

    import androidx.appcompat.app.AppCompatActivity;

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



    public class MainActivity extends AppCompatActivity {

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

        public void onClick(View view)
        {
            Button Vbutton =(Button)findViewById(R.id.Vbutton);
            long Ltime = System.currentTimeMillis() + 5*1000;
            while (System.currentTimeMillis()< Ltime)
            {
                synchronized (this)
                {
                    try{
                        wait(Ltime - System.currentTimeMillis());
                    }catch (Exception e){}
                }
            }
            TextView Vtext = (TextView)findViewById(R.id.Vtext);
            Vtext.setText("hello frands this is surbhi");
        }
    }
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.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"
        tools:context=".MainActivity">

        <TextView
            android:id="@+id/Vtext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="120dp"
            android:text="TextView"
            android:textSize="30sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/Vbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="296dp"
            android:onClick="click"
            android:text="Button"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.498"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/Vtext" />
    </androidx.constraintlayout.widget.ConstraintLayout>

why my app showing stopped in android phone? is there any bug or any error in my code when I'm running this code it shows Send bug report to Mi for analysis? This report may contain personally identifiable information. your report will be used to help fix this bug and will never be shared in any commercial context.

Upvotes: 0

Views: 259

Answers (1)

Gowrishankar
Gowrishankar

Reputation: 231

Please change the button's below statement which needs to indicate correct method when clicking actions made.

Please change in XML file of button from,

android:onClick="click"

to,

android:onClick="onClick"

Otherwise, please change method name in Java file as "click()"

Upvotes: 1

Related Questions