sorry but this is probably going to be a long one. Its my first time building an App with Android Studio and pretty much with Java. I’m trying to build a Chronometer. It was doing good and running properly but yesterday out of the blue it stopped working. Tried debugging it on several ways and cant go past it. Even more, I tried running other previous “simplier” programs that used to work fine and get the same error. It seems that it just cant start an app.
Its always the same routine, the bottom bar goes from “Builidng the Gradle” to “Terminating the app” and it will get STUCK on that process. Does anyone have an idea on how to proceed?
I deployed all the info from the logcat trying to find what went wrong but Im getting lost in all the logs.
Tried building a Chronometer program but now that Ive been trying it to isolate the source I have been moving back and forth previous attempts of the program that used to work and its doing exacty the same. and the issue keeps saying on the logcat it shows:
——–beginning of kernel
——–beginning of system
——–beginning of crash
——–beginning of main
At one point, reading on possible fixtures sombody posted that they recommend me to terminating the abd, and now a section of my code I cant call back. Mainly, do you know of any issues with the running of an app that could cause it?
Heres what I have for that program so far and it doesnt want to run:____ I got the idea from
https://youtu.be/Dr-VtCbev10?si=6NIXDvrXr5Fqqp8f Kudos to them.
`**Acticity Main activity_main.xml**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation='vertical'
tools:context=".MainActivity">
<TextView
android:id="@+id/TimerValue"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:textSize="40sp"
android:textColor="#000000"
android:text="0.00.000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/btnstart"
android:text="Start"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btnpause"
android:text="Pause"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btnlap"
android:text="Lap"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/Cycl"
android:text="Number of Cycles"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/MIN"
android:text="Total Minutes"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/SEC"
android:layout_gravity="center_horizontal"
android:text="Total Seconds"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/MILLIS"
android:layout_gravity="center_horizontal"
android:text="Total Millis"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/Cycles"
android:text="0"
android:textSize="25sp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/TextTotalMin"
android:text="0"
android:textSize="25sp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/TextTotalSec"
android:layout_gravity="center_horizontal"
android:text="0"
android:textSize="25sp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/TextTotalMilli"
android:layout_gravity="center_horizontal"
android:text="0"
android:textSize="25sp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
**ROW XML row.xml**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/txtContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text" />
</LinearLayout>
**MAIN ACTIVITY MainActivity.java**
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import java.util.ArrayList;
import java.util.Arrays;
public class MainActivity extends AppCompatActivity {
Button btnStart,btnPause,btnLap; //Declaration of variables to be associated to Objects
TextView txtTimer;
TextView TextTotalMin;
TextView TextTotalSec;
TextView TextTotalMill;
TextView TotalCycles;
Handler customHandler = new Handler();
LinearLayout container;
long startTime=0L, TimeinMilliseconds=0L,timeSwapBuff=0L,updateTime=0L; //Variables to display time
public ArrayList<Double> cycles=new ArrayList<>();
int mins,secs,milliseconds,totalmins=0,totalsecs=0,totalmillis=0,carrymins=0,carrysecs=0;
Runnable updateTimerTread=new Runnable() { //Time registering function!!!!!!
@Override
public void run() {
TimeinMilliseconds = SystemClock.uptimeMillis()-startTime;
updateTime = timeSwapBuff+TimeinMilliseconds;
//int secs=(int)(updateTime/1000);
secs=(int) (updateTime/1000);
//int mins=secs/60;
mins=secs/60;
secs%=60;
//int milliseconds=(int)(updateTime%1000);
milliseconds=(int)(updateTime%1000);
txtTimer.setText(""+mins+"."+String.format("%2d",secs)+"."+String.format("%3d",milliseconds));
customHandler.postDelayed(this,0);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
btnStart=(Button) findViewById(R.id.btnstart); //Address linked to physical Object (Variable BtnStart to Button that says start)
btnPause=(Button) findViewById(R.id.btnpause);
btnLap=(Button) findViewById(R.id.btnlap);
txtTimer=(TextView) findViewById(R.id.TimerValue);
TextTotalMin=(TextView) findViewById(R.id.TextTotalMin);
TextTotalSec=(TextView) findViewById(R.id.TextTotalSec);
TextTotalMill=(TextView) findViewById(R.id.TextTotalMilli);
TotalCycles=(TextView) findViewById(R.id.Cycles);
container=(LinearLayout)findViewById(R.id.container);
btnStart.setOnClickListener(new View.OnClickListener() { //Declaration of Method, what do we want the variable to do when Object gets clicked
@Override
public void onClick(View v) {
startTime= SystemClock.uptimeMillis();
customHandler.postDelayed(updateTimerTread,0);
}
});
btnPause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timeSwapBuff+=TimeinMilliseconds;
customHandler.removeCallbacks(updateTimerTread);
LayoutInflater inflater =(LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View addView = inflater.inflate(R.layout.row,null);
TextView txtValue=(TextView) addView.findViewById(R.id.txtContent);
txtValue.setText((txtTimer.getText()));
cycles.addAll(Arrays.asList((Double.valueOf(mins)),(Double.valueOf(secs)),(Double.valueOf(milliseconds))));
System.out.println(cycles);
//System.out.println(cycles.size());
for (int i =0;i<cycles.size();i+=3){
totalmins +=cycles.get(i);
//System.out.println(totalmins);
}
for (int i =1;i<cycles.size();i+=3){
totalsecs +=cycles.get(i);
//System.out.println(totalsecs);
}
for (int i =2;i<cycles.size();i+=3){
totalmillis +=cycles.get(i);
//System.out.println(totalmillis);
}
//NEW CRASHING REASON
if (totalmillis/1000>=1){
carrysecs=totalmillis/1000;
totalmillis=totalmillis%1000;
}
if ((totalsecs)/60>=1){
carrymins=(totalsecs)/60;
totalsecs=(totalsecs)%60;
}
TextTotalMin.setText(String.valueOf(totalmins+carrymins));
TextTotalSec.setText(String.valueOf(totalsecs+carrysecs));
TextTotalMill.setText(String.valueOf(totalmillis));
TotalCycles.setText(String.valueOf((cycles.size()/3)));
//
System.out.println(totalmins);
System.out.println(totalsecs);
System.out.println(totalmillis);
totalmins=0; totalsecs=0; totalmillis=0; carrymins=0; carrysecs=0;
container.addView(addView);
}
});
btnLap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater =(LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View addView = inflater.inflate(R.layout.row,null);
TextView txtValue=(TextView) addView.findViewById(R.id.txtContent);
txtValue.setText((txtTimer.getText()));
container.addView(addView);
}
});
}
}`