java.lang.Throwable: setStateLocked - java

In my app, i have a SplashScreen activity. I have setStateLocked error when i clicked on the app. I'm using Fortune Ship MTN-S730 running android 5.1.
Here is the onCreate method
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen); /* logcat says error on this line */
}
The says the says that error is on the line with
setContentView(R.layout.activity_splash_screen);
here is the output from the logcat
setStateLocked: wasEnabled = false, mIsEnabled = false, wasTouchExplorationEnabled = false,
mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false
java.lang.Throwable: setStateLocked
at android.view.accessibility.AccessibilityManager.setStateLocked(AccessibilityManager.java:553)
at android.view.accessibility.AccessibilityManager.tryConnectToServiceLocked(AccessibilityManager.java:636)
at android.view.accessibility.AccessibilityManager.<init>(AccessibilityManager.java:226)
at android.view.accessibility.AccessibilityManager.getInstance(AccessibilityManager.java:206)
at android.view.View.setFlags(View.java:9843)
at android.view.ViewGroup.initViewGroup(ViewGroup.java:536)
at android.view.ViewGroup.<init>(ViewGroup.java:525)
at android.view.ViewGroup.<init>(ViewGroup.java:520)
at android.view.ViewGroup.<init>(ViewGroup.java:516)
at android.view.ViewGroup.<init>(ViewGroup.java:512)
at android.widget.FrameLayout.<init>(FrameLayout.java:119)
at com.android.internal.policy.impl.PhoneWindow$DecorView.<init>(PhoneWindow.java:2326)
at com.android.internal.policy.impl.PhoneWindow.generateDecor(PhoneWindow.java:3460)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3846)
at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:2042)
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:371)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:320)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:281)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.cm_floraison.brandbook.gesu.SplashScreenActivity.onCreate(SplashScreenActivity.java:101)
at android.app.Activity.performCreate(Activity.java:6092)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
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)
Here is the manifest declaration of the activity
<activity
android:name=".gesu.SplashScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Also the content of activity_splash_screen.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
tools:context="com.cm_toure.myapp.gesu.SplashScreenActivity">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/fullscreen_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:contentDescription="#string/app_logo"
android:foregroundGravity="center"
android:keepScreenOn="true"
android:src="#drawable/ic_logo_brandbook_paysage_sur_fond_blanc"
/>
</LinearLayout>
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="#+id/fullscreen_content_controls"
style="?metaButtonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="vertical"
tools:ignore="UselessParent">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginTop="10dp"
android:indeterminate="true"
android:indeterminateDrawable="#drawable/splash_spinner_style"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="50dp"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:text="#string/powered_by"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="18sp"/>
</LinearLayout>
</FrameLayout>
</FrameLayout>

Related

Truecaller like alert dialog in dart

I am trying to implement a true caller like alert dialog in flutter. Since I am very new to flutter+dart, I was looking for any out of the box implementation. So far I have found system_alert_window but this creates the alert dialogue in JAVA and uses platform channels to communicate with it. My question is that if it's possible to do this is pure flutter+dart.
I do not know if this kind of dialogues has any special names, also in truecaller the dialogue is shown regardless the app is running or not. Can anyone provide some pointers?
Thanks
No you can't do with flutter
You can only go with Java.
Flollow the steps
your project > android > app > src > main > AndroidManifest.xml
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
add this permission on your Androidmanifest.xml file
after adding the permission add the below receiver class
<receiver android:name=".CallReceiver"
android:enabled="true"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
the receiver class
ServiceReceiver.Java
public class ServiceReceiver extends BroadcastReceiver {
#Override
public void onReceive(final Context context, Intent intent) {
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(new PhoneStateListener(){
#Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
System.out.println("incomingNumber : "+incomingNumber);
WindowManager windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE);
View view = LayoutInflater.from(context).inflate(R.layout.popup_window, null); // Code for inflating xml layout
int LAYOUT_FLAG;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE;
}
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
LAYOUT_FLAG,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
windowManager.addView(view, params);
}
},PhoneStateListener.LISTEN_CALL_STATE);
}
}
add the below xml file on the folder
your project > android > app > src > main > res > layout > popup_window.xml
popup_window.xml
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:background="#000000"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/popup_color"
android:orientation="vertical"
tools:ignore="UselessParent">
<LinearLayout
android:id="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/paymentlogo"
android:layout_width="65dp"
android:layout_height="65dp"
android:scaleType="fitCenter"
android:src="#drawable/rsoft_logo"
app:srcCompat="#drawable/rsoft_logo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="3dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal">
<TextView
android:id="#+id/lbl_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="6dp"
android:layout_weight="0.3"
android:singleLine="true"
android:text="Anand"
android:textColor="#000000"
android:textSize="20sp" />
<ImageView
android:id="#+id/iv_close"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.7"
android:src="#drawable/ic_close_black" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/txt_record_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:visibility="gone"
tools:ignore="HardcodedText" />
<View
android:id="#+id/btw_view"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_gravity="center"
android:background="#bab9b9" />
<LinearLayout
android:id="#+id/details_adp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="3dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:padding="3dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/tv_icon"
android:layout_width="17dp"
android:layout_marginTop="4dp"
android:layout_height="17dp"
android:layout_weight="1"
android:textColor="#000000"
android:src="#android:drawable/sym_call_incoming"
android:textSize="10sp" />
<TextView
android:id="#+id/tv_mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:text="7667673691"
android:padding="0dp"
android:textColor="#000000"
android:textSize="16sp" />
</LinearLayout>
<TextView
android:id="#+id/tv_mobile_"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:text="Incomingg"
android:textColor="#000000"
android:textSize="12sp" />
<!-- <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="4dp"
android:padding="3dp">
<ImageView
android:id="#+id/iv_im"
android:layout_width="14dp"
android:layout_height="14dp"
android:src="#drawable/sim" />
<TextView
android:id="#+id/tv_sim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="Incomingg"
android:textColor="#000000"
android:textSize="12sp" />
</LinearLayout>-->
</LinearLayout>
<TextView
android:id="#+id/tv_lead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="Save As Lead"
android:background="#drawable/rounded_btn"
android:padding="8dp"
android:layout_marginTop="6dp"
android:textColor="#000000"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
You can use flutter_overlay_window. Its JAVA only but works fine. The example app has a truecaller like overlay demo. The other answer is correct, no it can't be done in pure flutter.

When I click the button the second Activity doesn't show up and my Android Studio App closes

When I click the cardView with the id addNotice in the activity_main.xml the second Activity UploadNotice is supposed to show up, but my Android studio app closes and the second Activity that I've created never shows up. I'm new to Android Studio and Java so I would appreciate it a lot if anyone can help me!
Here is my MainActivity.java :
package com.example.adminuniversityapp;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
CardView uploadNptice;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uploadNptice = findViewById(R.id.addNotice);
uploadNptice.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.addNotice:
Intent intent = new Intent( MainActivity.this,UploadNotice.class);
startActivity(intent);
break;
}
}
}
and Here is my 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.card.MaterialCardView
android:id="#+id/addNotice"
android:layout_width="130dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="135dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/circle_green"
android:padding="15dp"
android:src="#drawable/ic_notice" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/lightGray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Upload Notice"
android:textColor="#color/textColor"
android:textStyle="bold" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="#+id/addGalleryImage"
android:layout_width="130dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/circle_purple"
android:padding="15dp"
android:src="#drawable/ic_gallery"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/lightGray"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Upload Image"
android:textColor="#color/textColor"
android:textStyle="bold"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.card.MaterialCardView
android:id="#+id/addEbook"
android:layout_width="130dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/circle_pink"
android:padding="15dp"
android:src="#drawable/ic_upload"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/lightGray"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Upload Ebook"
android:textColor="#color/textColor"
android:textStyle="bold"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="#+id/faculty"
android:layout_width="130dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/circle_yellow"
android:padding="15dp"
android:src="#drawable/ic_group"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/lightGray"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Update Faculty"
android:textColor="#color/textColor"
android:textStyle="bold"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.card.MaterialCardView
android:id="#+id/deleteNotice"
android:layout_width="130dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardElevation="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/cicle_red"
android:padding="15dp"
android:src="#drawable/ic_delete"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/lightGray"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Delete Notice"
android:textColor="#color/textColor"
android:textStyle="bold"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</LinearLayout>
Also here is the AndroidManifest.xml just in case :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.adminuniversityapp">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<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/Theme.AdminUniversityApp">
<activity android:name=".UploadNotice" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is the second Activity UploadNotice.java:
package com.example.adminuniversityapp;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;
import java.io.IOException;
public class UploadNotice extends AppCompatActivity {
private CardView addImage;
private ImageView noticeImageView;
private final int REQ = 1;
private Bitmap bitmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload_notice);
addImage = findViewById(R.id.addImage);
noticeImageView = findViewById(R.id.noticeImageView);
addImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openGallery();
}
});
}
private void openGallery() {
Intent pickImage = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickImage, REQ);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQ && resultCode == RESULT_OK){
Uri uri = data.getData();
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uri);
} catch (IOException e) {
e.printStackTrace();
}
noticeImageView.setImageBitmap(bitmap);
}
}
}
and Here is the second Activity Xml code :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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=".UploadNotice"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
android:id="#+id/addImage"
android:layout_width="130dp"
android:layout_height="150dp"
android:layout_margin="10dp"
app:cardElevation="5dp"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/circle_purple"
android:padding="15dp"
android:src="#drawable/ic_image"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#color/lightGray"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="5dp"
android:text="Select Image"
android:textColor="#color/textColor"
android:textStyle="bold"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.Material3.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/noticeTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notice title" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Upload Notice"
android:layout_marginTop="16dp"
android:textAllCaps="false"
android:id="#+id/uploadNoticeBtn"/>
<com.google.android.material.card.MaterialCardView
android:layout_marginTop="16dp"
android:layout_width="match_parent"
android:layout_height="400dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:id="#+id/noticeImageView"/>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</ScrollView>
And this is the Logcat when I click the Cardview button
2022-02-26 16:09:00.615 26302-26302/com.example.adminuniversityapp I/Timeline: Timeline: Activity_launch_request time:449776768
2022-02-26 16:09:00.633 26302-26357/com.example.adminuniversityapp V/FA: Recording user engagement, ms: 60057
2022-02-26 16:09:00.636 26302-26357/com.example.adminuniversityapp V/FA: Using local app measurement service
2022-02-26 16:09:00.641 26302-26357/com.example.adminuniversityapp V/FA: Activity paused, time: 598904714
2022-02-26 16:09:00.651 26302-26302/com.example.adminuniversityapp V/FA: onActivityCreated
2022-02-26 16:09:00.656 26302-26302/com.example.adminuniversityapp D/DecorView[]: getWindowModeFromSystem windowmode is 1
2022-02-26 16:09:00.667 26302-26357/com.example.adminuniversityapp V/FA: Connection attempt already in progress
2022-02-26 16:09:00.681 26302-26302/com.example.adminuniversityapp E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-02-26 16:09:00.687 26302-26302/com.example.adminuniversityapp E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-02-26 16:09:00.693 26302-26302/com.example.adminuniversityapp E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-02-26 16:09:00.722 26302-26302/com.example.adminuniversityapp D/AndroidRuntime: Shutting down VM
2022-02-26 16:09:00.724 26302-26302/com.example.adminuniversityapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.adminuniversityapp, PID: 26302
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.adminuniversityapp/com.example.adminuniversityapp.UploadNotice}: android.view.InflateException: Binary XML file line #55 in com.example.adminuniversityapp:layout/activity_upload_notice: Binary XML file line #55 in com.example.adminuniversityapp:layout/activity_upload_notice: Error inflating class com.google.android.material.textfield.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3580)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3752)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2191)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8049)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
Caused by: android.view.InflateException: Binary XML file line #55 in com.example.adminuniversityapp:layout/activity_upload_notice: Binary XML file line #55 in com.example.adminuniversityapp:layout/activity_upload_notice: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #55 in com.example.adminuniversityapp:layout/activity_upload_notice: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:856)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1012)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:963)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1142)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1103)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1145)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1103)
at android.view.LayoutInflater.inflate(LayoutInflater.java:684)
at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:706)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.example.adminuniversityapp.UploadNotice.onCreate(UploadNotice.java:32)
at android.app.Activity.performCreate(Activity.java:8142)
at android.app.Activity.performCreate(Activity.java:8114)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1308)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3553)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3752)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2191)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8049)
at java.lang.reflect.Method.invoke(Native Method)
2022-02-26 16:09:00.725 26302-26302/com.example.adminuniversityapp E/AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
Caused by: java.lang.IllegalArgumentException: This component requires that you specify a valid TextAppearance attribute. Update your app theme to inherit from Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTextAppearance(ThemeEnforcement.java:185)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:116)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:474)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:433)
... 30 more
2022-02-26 16:09:00.749 26302-26302/com.example.adminuniversityapp I/Process: Sending signal. PID: 26302 SIG: 9
there are two themes.xml :
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.AdminUniversityApp" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.AdminUniversityApp" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_200</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_200</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
In the styles.xml file, change the theme to something like this:
<style name="Theme.AdminUniversityApp" parent="Theme.Material3.DayNight">
...
</style>

Why my application suddenly getting stopped? [duplicate]

This question already has answers here:
findViewById returns null
(4 answers)
Can not find a View with findViewById()
(4 answers)
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 3 years ago.
My apps unfortunately stopped after right I put the OnClickListener
My problem shows :
at com.example.whatisthat.Dashboard.onCreate(Dashboard.java:23)
Error :
LoginBtn.setOnClickListener(this);
Dashboard.java
package com.example.whatisthat;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class Dashboard extends AppCompatActivity implements View.OnClickListener
{
private CardView LoginBtn, CaptureBtn, AboutBtn, FeedbackBtn, IgBtn, HelpBtn;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//DEFINE CARDS
//ADD CLICK LISTENER TO THE CARDS
LoginBtn = findViewById(R.id.Login);
LoginBtn.setOnClickListener(this);
CaptureBtn = findViewById(R.id.Capture);
CaptureBtn.setOnClickListener(this);
AboutBtn = findViewById(R.id.About);
AboutBtn.setOnClickListener(this);
FeedbackBtn = findViewById(R.id.Feedback);
FeedbackBtn.setOnClickListener(this);
IgBtn = findViewById(R.id.Ig);
IgBtn.setOnClickListener(this);
HelpBtn = findViewById(R.id.Help);
HelpBtn.setOnClickListener(this);
}
#Override
public void onClick(View view)
{
Intent i;
switch (view.getId())
{
case R.id.Login : i = new Intent(this,Login1.class);
startActivity(i);
break;
case R.id.Capture : i = new Intent(this, Capture.class);
startActivity(i);
break;
case R.id.About : i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.Feedback : i = new Intent(this, Feedback.class);
startActivity(i);
break;
case R.id.Ig : i = new Intent(this, Instagram.class);
startActivity(i);
break;
case R.id.Help : i = new Intent(this, Help.class);
startActivity(i);
break;
default:break;
}
}
}
activity_dashboard.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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=".Dashboard">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="230dp"
android:orientation="vertical"
android:gravity="center"
android:background="#6A287E">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:src="#drawable/iconfyp"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DASHBOARD"
android:textColor="#color/colorAccent"
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="18sp"
android:layout_marginTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="215dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:id="#+id/Login"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView1"
android:layout_height="50dp"
android:src="#drawable/people"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN"
android:textSize="16sp"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonLogin"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/Capture"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView2"
android:layout_height="50dp"
android:src="#drawable/cameraa"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAPTURE"
android:textSize="16sp"
android:layout_below="#+id/imageView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonCapture"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:id="#+id/About"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView3"
android:layout_height="50dp"
android:src="#drawable/aboutt"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABOUT"
android:textSize="16sp"
android:layout_below="#+id/imageView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonAbout"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/Feedback"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView4"
android:layout_height="50dp"
android:src="#drawable/feedback"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FEEDBACK "
android:textSize="16sp"
android:layout_below="#+id/imageView4"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonFeedback"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="135dp"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<androidx.cardview.widget.CardView
android:id="#+id/Ig"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView5"
android:layout_height="50dp"
android:src="#drawable/instagram"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="INSTAGRAM"
android:textSize="16sp"
android:layout_below="#+id/imageView5"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonInstagram"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/Help"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="50dp"
android:id="#+id/imageView6"
android:layout_height="50dp"
android:src="#drawable/help"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELP"
android:textSize="16sp"
android:layout_below="#+id/imageView6"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buttonHelp"
android:background="#android:color/transparent"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<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=".Help"
android:label="#string/Help"/>
<activity android:name=".Instagram"
android:label="#string/Instagram"/>
<activity android:name=".Feedback"
android:label="#string/Feedback"/>
<activity android:name=".About"
android:label="#string/About"/>
<activity android:name=".Capture"
android:label="#string/Capture"/>
<activity android:name=".Login1"
android:label="#string/Login1"/>
<activity android:name=".Dashboard"
android:label="#string/Dashboard"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
In your onCreate() method there isn't
setContentView(R.layout.activity_dashboard);
before the methods findViewById() which return null.
Use:
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard); //<-- add the method
LoginBtn = findViewById(R.id.Login);

Stopwatch buttons crash in Android Studio

Happy day to all of you.
I have been attempting to make a stopwatch application as my first one, while using the Chronometer function. The problem is, when I click on the Start button (while the app is running on tablet), it crashes. The situation is similar to the others.
I am not sure how I should fix this, and I greatly appreciate your help.
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<ImageView
android:id="#+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="#color/colorPrimaryDark" />
<LinearLayout
android:id="#+id/navcon"
android:layout_width="match_parent"
android:layout_height="92dp"
android:orientation="vertical">
<ImageView
android:id="#+id/navbar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#color/colorPrimary" />
</LinearLayout>
<LinearLayout
android:id="#+id/navtextcon"
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="vertical">
<TextView
android:id="#+id/navtext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="rocket.studios"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
<LinearLayout
android:id="#+id/chronocon"
android:layout_width="match_parent"
android:layout_height="95dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="78dp"
android:orientation="vertical">
<Chronometer
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textColor="#android:color/white"
android:textSize="60sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/startbcon"
android:layout_width="match_parent"
android:layout_height="118dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="155dp"
android:orientation="vertical"
android:padding="20dp">
<Button
android:id="#+id/startb"
android:layout_width="match_parent"
android:layout_height="68dp"
android:background="#color/colorPrimary"
android:text="#string/start"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/stopbcon"
android:layout_width="match_parent"
android:layout_height="118dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:padding="20dp">
<Button
android:id="#+id/stopb"
android:layout_width="match_parent"
android:layout_height="68dp"
android:background="#color/colorPrimary"
android:text="#string/stop"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/resetbcon"
android:layout_width="match_parent"
android:layout_height="118dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="158dp"
android:orientation="vertical"
android:padding="20dp">
<Button
android:id="#+id/resetb"
android:layout_width="match_parent"
android:layout_height="68dp"
android:background="#color/colorPrimary"
android:text="#string/reset"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
MainActivity.java :
package testing.ezekieralt.com.stopwatcher;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.ButtonBarLayout;
import android.view.View;
import android.widget.Button;
import android.widget.Chronometer;
import android.os.SystemClock;
//chronometer is...guess it
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Chronometer chronometer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.startb).setOnClickListener(this);
findViewById(R.id.resetb).setOnClickListener(this);
findViewById(R.id.stopb).setOnClickListener(this);
chronometer = findViewById(R.id.chronometer);
}
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.stopb:
chronometer.stop();
break;
case R.id.startb:
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.start();
break;
case R.id.resetb:
chronometer.setBase(SystemClock.elapsedRealtime());
break;
}
}
}
AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="testing.ezekieralt.com.stopwatcher">
<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>
You didn't added id to your Chronometer. Add id to your Chronometer
<Chronometer
android:id="#+id/chronometer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textColor="#android:color/white"
android:textSize="60sp"
android:textStyle="bold" />

Passing Radiobutton and Checkbox values to another activity

I am new to android. Here am trying to pass the radiobutton and Checkbox values from one activity to another activity. Its not showing any error but when I run it simply gets closed. Any help would be appreciated.Here I have posted the complete code..
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;
public class MainActivity extends Activity {
Intent obj = new Intent(this, SecondActivity.class);
Bundle extras = new Bundle();
RadioButton male, female, single, married;
CheckBox twelveth, bE, mE;
String s1="+2";
String s2="B.E.";
String s3="M.E.";
StringBuilder s;
String str;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
male = (RadioButton) findViewById(R.id.male);
female = (RadioButton) findViewById(R.id.female);
single = (RadioButton) findViewById(R.id.single);
married = (RadioButton) findViewById(R.id.married);
twelveth = (CheckBox) findViewById(R.id.twelveth);
bE = (CheckBox) findViewById(R.id.BE);
mE = (CheckBox) findViewById(R.id.ME);
str=s.toString();
extras.putString("Education",str);
}
public void onGenderClicked(View v) {
boolean checked = ((RadioButton) v).isChecked();
switch (v.getId()) {
case R.id.male:
if (checked)
extras.putString("Gender", "Male");
break;
case R.id.female:
if (checked)
extras.putString("Gender", "Female");
break;
}
}
public void onStatusClicked(View v) {
boolean checked = ((RadioButton) v).isChecked();
switch (v.getId()) {
case R.id.single:
if (checked)
extras.putString("Status", "Single");
break;
case R.id.married:
if (checked)
extras.putString("Status", "Married");
break;
}
}
public void ButtonClick(View v) {
obj.putExtras(extras);
startActivity(obj);
}
public void onCheckBoxClicked(View v)
{
boolean checked=((CheckBox)v).isChecked();
switch(v.getId())
{
case R.id.twelveth:
if(checked)
{
s.append("\n"+s1);
}
break;
case R.id.BE:
if(checked)
{
s.append("\n"+s2);
}
break;
case R.id.ME:
if(checked)
{
s.append("\n"+s3);
}
break;
}
str=s.toString();
extras.putString("Education",str);
}
}
SecondActivity
package com.example.aravindpraveen.buttonsandboxes;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class SecondActivity extends Activity {
TextView tvGender,tvStatus,tvEducation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
tvGender=(TextView)findViewById(R.id.tvGender);
tvStatus=(TextView)findViewById(R.id.tvStatus);
tvEducation=(TextView)findViewById(R.id.tvEducation);
Intent obj1=getIntent();
Bundle extras=obj1.getExtras();
String gender=extras.getString("Gender");
String status=extras.getString("Starus");
String education=extras.getString("Education");
tvGender.setText(gender);
tvStatus.setText(status);
tvEducation.setText(education);
}
}
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.aravindpraveen.buttonsandboxes" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#6457d962"
android:orientation="vertical">
<TextView android:text="#string/b_b"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="40sp"
android:background="#f62dd93c"
android:textColor="#c34c27e6"
android:gravity="center"/>
<Space
android:layout_width="match_parent"
android:layout_height="15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/gender"
android:textSize="40sp"
android:gravity="center"
android:textColor="#000000"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rg_gender">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/male"
android:text="#string/male"
android:textSize="30sp"
android:checked="true"
android:onClick="onGenderClicked"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/female"
android:text="#string/female"
android:textSize="30sp"
android:onClick="onGenderClicked"/>
</RadioGroup>
<Space
android:layout_width="match_parent"
android:layout_height="15dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:text="#string/M_status"
android:textColor="#000000"
android:gravity="center"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rg_status">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/single"
android:text="#string/single"
android:textSize="30sp"
android:checked="true"
android:onClick="onStatusClicked"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/married"
android:text="#string/married"
android:textSize="30sp"
android:onClick="onStatusClicked"/>
</RadioGroup>
<Space
android:layout_width="match_parent"
android:layout_height="15dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:text="#string/education"
android:textColor="#000000"
android:gravity="center"
/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/twelveth"
android:textSize="30sp"
android:id="#+id/twelveth"
android:onClick="onCheckBoxClicked"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/bE"
android:textSize="30sp"
android:id="#+id/BE"
android:onClick="onCheckBoxClicked"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/mE"
android:textSize="30sp"
android:id="#+id/ME"
android:onClick="onCheckBoxClicked"/>
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/submit"
android:text="#string/submit"
android:layout_gravity="center"
android:onClick="ButtonClick"/>
</LinearLayout>
second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f4dbde"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40sp"
android:background="#fba1a1"
android:text="#string/heading"
android:gravity="center"
android:textColor="#ffffff"/>
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/gender"
android:textSize="40sp"
android:gravity="center"
android:textColor="#ffffff"
android:background="#f7beae"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:paddingTop="20dp"
android:gravity="center"
android:id="#+id/tvGender"/>
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/M_status"
android:textSize="40sp"
android:gravity="center"
android:textColor="#ffffff"
android:background="#f7beae"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:paddingTop="20dp"
android:gravity="center"
android:id="#+id/tvStatus"/>
<Space
android:layout_width="match_parent"
android:layout_height="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/education"
android:textSize="40sp"
android:gravity="center"
android:textColor="#ffffff"
android:background="#f7beae"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:paddingTop="20dp"
android:gravity="center"
android:id="#+id/tvEducation"/>
</LinearLayout>
LogCat
02-03 11:39:42.859 1135-1135/com.example.aravindpraveen.buttonsandboxes D/AndroidRuntime﹕ Shutting down VM
02-03 11:39:42.863 1135-1135/com.example.aravindpraveen.buttonsandboxes W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4c2c648)
02-03 11:39:42.899 1135-1135/com.example.aravindpraveen.buttonsandboxes E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.aravindpraveen.buttonsandboxes/com.example.aravindpraveen.buttonsandboxes.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.ContextWrapper.getPackageName(ContextWrapper.java:135)
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:3662)
at com.example.aravindpraveen.buttonsandboxes.MainActivity.<init>(MainActivity.java:15)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
from the second activity declare in Manifest, remove tags
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
i think starting activity as MAIN while it's not MAIN may cause this problem
also in documentaion
Activity Action: Start as a main entry point, does not expect to receive data.
EDIT:
also move
str=s.toString();
extras.putString("Education",str);
inside onClick that starts the 2nd activity

Categories

Resources