"Unfortunately MyApp has stopped" when I Press A Button [duplicate] - java

This question already has answers here:
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
Closed 4 years ago.
I made a quiz game with codes I found on github because I'm a newbie and I want to learn programming.
So, when I press the start button game crashes. I tried it without the other classes but it still crashes. There is my MainActivity class, MainActivity xml and AndroidManifest.
MainActivity.java
package com.proje.bilgiyarismasi.bilgiyarismasi;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class MainActivity extends AppCompatActivity {
ImageButton baslat,ayarlar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
baslat = findViewById(R.id.baslatButonu);
ayarlar = findViewById(R.id.ayarlarButonu);
baslat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, SoruAlani.class);
startActivity(intent);
finish();
}
});
ayarlar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,Ayarlar.class);
startActivity(intent);
finish();
}
});
}
}
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"
android:background="#color/deepPurple"
tools:context="com.proje.bilgiyarismasi.bilgiyarismasi.MainActivity"
tools:layout_editor_absoluteY="25dp"
tools:layout_editor_absoluteX="0dp">
<TextView
android:id="#+id/logoIsim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:text="#string/logoIsim"
android:textColor="#color/orenji"
android:textSize="50sp"
tools:layout_editor_absoluteX="150dp"
tools:layout_editor_absoluteY="28dp" />
<ImageButton
android:id="#+id/baslatButonu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/logoIsim"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"
app:srcCompat="#drawable/menu_1"
android:adjustViewBounds="true"
/>
<ImageView
android:id="#+id/playButton"
android:layout_width="72dp"
android:layout_height="72dp"
app:srcCompat="#drawable/play_button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="#+id/baslatButonu"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="2dp"
android:gravity="center"/>
<TextView
android:id="#+id/basla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/baslatButonu"
android:layout_alignEnd="#id/baslatButonu"
android:layout_alignLeft="#id/baslatButonu"
android:layout_alignRight="#id/baslatButonu"
android:layout_alignStart="#id/baslatButonu"
android:layout_alignTop="#id/baslatButonu"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="1dp"
android:gravity="center"
android:text="#string/baslat"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
/>
<ImageButton
android:id="#+id/ayarlarButonu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/baslatButonu"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
app:srcCompat="#drawable/menu_1"
android:adjustViewBounds="true"
/>
<TextView
android:id="#+id/ayarlar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/ayarlarButonu"
android:layout_alignEnd="#id/ayarlarButonu"
android:layout_alignLeft="#id/ayarlarButonu"
android:layout_alignRight="#id/ayarlarButonu"
android:layout_alignStart="#id/ayarlarButonu"
android:layout_alignTop="#id/ayarlarButonu"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="1dp"
android:gravity="center"
android:text="#string/ayarlar"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ayarla"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignBottom="#id/ayarlarButonu"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="2dp"
app:srcCompat="#drawable/settings_button"
android:adjustViewBounds="true"
/>
<TextView
android:id="#+id/sosyalMedya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ayarlarButonu"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="#string/sosyalMedya"
android:textAlignment="center"
android:textStyle="bold"
android:gravity="center"/>
<ImageButton
android:id="#+id/facebookLogo"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignTop="#id/sosyalMedya"
app:srcCompat="#drawable/facebook_logo"
android:adjustViewBounds="true"
android:background="#null"
android:scaleType="fitCenter"
android:layout_toLeftOf="#id/sosyalMedya"
android:layout_toStartOf="#id/sosyalMedya"
android:layout_marginTop="30dp"
/>
<ImageButton
android:id="#+id/twitterLogo"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignTop="#+id/sosyalMedya"
app:srcCompat="#drawable/twitter_logo"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:background="#null"
android:layout_centerInParent="true"
android:layout_marginTop="30dp"
/>
<ImageButton
android:id="#+id/slackLogo"
android:layout_width="72dp"
android:layout_height="72dp"
app:srcCompat="#drawable/slack_logo"
android:layout_alignTop="#+id/sosyalMedya"
android:adjustViewBounds="true"
android:background="#null"
android:scaleType="fitCenter"
android:layout_toRightOf="#id/sosyalMedya"
android:layout_toEndOf="#id/sosyalMedya"
android:layout_marginTop="30dp"
/>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.proje.bilgiyarismasi.bilgiyarismasi">
<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=".TekrarOyna" />
<activity android:name=".OyunKazanma" />
<activity android:name=".SoruAlani" />
<activity android:name=".SureBitti">
</activity>
</application>
</manifest>
logcat
05-25 12:28:18.414 6393-6393/com.proje.bilgiyarismasi.bilgiyarismasi
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.proje.bilgiyarismasi.bilgiyarismasi, PID: 6393
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.proje.bilgiyarismasi.bilgiyarismasi/com.proje.bilgiyarismasi.bilgiyarismasi.SoruAlani}:
java.lang.RuntimeException: Font asset not found fonts/Bariol_Regular.otf
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.RuntimeException: Font asset not found
fonts/Bariol_Regular.otf
at android.graphics.Typeface.createFromAsset(Typeface.java:190)
at com.proje.bilgiyarismasi.bilgiyarismasi.SoruAlani.onCreate(SoruAlani.java:51)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
05-25 12:28:20.016 4207-6527/com.android.providers.calendar E/SQLiteLog:
(284) automatic index on view_events(_id)
05-25 12:28:26.129 1535-1602/system_process E/InputDispatcher: channel
'2cf4e81e
com.proje.bilgiyarismasi.bilgiyarismasi/com.proje.bilgiyarismasi.bilgiyarismasi.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
Thanks for your help.

You have not casted the image buttons correctly.
Use this in onCreate()
baslat = (ImageButton)findViewById(R.id.baslatButonu);
ayarlar =(ImageButton) findViewById(R.id.ayarlarButonu);
And Declare this activity in manifest
<activity android:name=".Ayarlar">
From the logcat
**java.lang.RuntimeException: Font asset not found fonts/Bariol_Regular.otf**
Add this font file also
Bariol_Regular.otf
Check this link please
How to use custom font in Android Studio

Related

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>

App Crash when i click button to change activity [duplicate]

This question already has answers here:
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
What is a NullPointerException, and how do I fix it?
(12 answers)
Null pointer Exception - findViewById()
(12 answers)
Closed 4 years ago.
I'm sorry if i'm not so accurate but this is my first app.
The problem is: when i press a button to change activity the app crash.
Can someone help me? Thanks for all!!
If you wanna have more information tell me and I try to explain better.
CODE:
MAIN ACTIVITY
package com.example.principale.designazioni;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button invia = (Button) findViewById(R.id.buttInvia);
invia.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openActivityPage1();
}
});
}
public void openActivityPage1() {
Intent intent = new Intent (getApplicationContext(), Page1.class);
startActivity(intent);
}
}
XML MAIN ACTIVITY
<?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"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="73dp">
<ImageView
android:id="#+id/imageView4"
android:layout_width="231dp"
android:layout_height="229dp"
android:layout_marginEnd="8dp"
android:adjustViewBounds="false"
android:contentDescription='#string tools:ignore="ContentDescription"'
android:cropToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.146"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.04"
app:srcCompat="#mipmap/logo_grigio" />
<TextView
android:id="#+id/textView2"
android:layout_width="272dp"
android:layout_height="51dp"
android:fontFamily="monospace"
android:text="Disponibilità"
android:textAlignment="center"
android:textColor="#android:color/holo_orange_dark"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.818"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView4"
app:layout_constraintVertical_bias="0.093" />
<Button
android:id="#+id/buttInvia"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="monospace"
android:text="Invia"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#android:color/holo_orange_dark"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2"
app:layout_constraintVertical_bias="0.482" />
</android.support.constraint.ConstraintLayout>
ACTIVITY PAGE1
package com.example.principale.designazioni;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Page1 extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page1);
EditText mail = (EditText) findViewById(R.id.editTextMail);
EditText nome = (EditText) findViewById(R.id.editTextNome);
EditText cognome = (EditText) findViewById(R.id.editTextCognome);
EditText tessera = (EditText) findViewById(R.id.editTextTessera);
Button avanti = (Button) findViewById(R.id.buttInvia);
Bundle bundle = new Bundle();
bundle.putString("mail", mail.getText().toString());
bundle.putString("nome", nome.getText().toString());
bundle.putString("cognome", cognome.getText().toString());
bundle.putString("tessera", tessera.getText().toString());
avanti.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openActivityPage2();
}
});
}
public void openActivityPage2() {
Intent intent = new Intent (getApplicationContext(), Page2.class);
startActivity(intent);
}
}
XML ACTIVITY PAGE1
<?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"
tools:context=".Page1">
<TextView
android:id="#+id/textView3"
android:layout_width="71dp"
android:layout_height="27dp"
android:fontFamily="monospace"
android:text="E-Mail"
android:textAlignment="textStart"
android:textColor="#android:color/holo_orange_dark"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.093"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.06" />
<TextView
android:id="#+id/textView4"
android:layout_width="96dp"
android:layout_height="27dp"
android:fontFamily="monospace"
android:text="Cognome"
android:textAlignment="textStart"
android:textColor="#android:color/holo_orange_dark"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.102"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.44" />
<TextView
android:id="#+id/textView6"
android:layout_width="71dp"
android:layout_height="27dp"
android:fontFamily="monospace"
android:text="Numero di Tessera"
android:textAlignment="textStart"
android:textColor="#android:color/holo_orange_dark"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.093"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.629" />
<TextView
android:id="#+id/textView5"
android:layout_width="71dp"
android:layout_height="27dp"
android:fontFamily="monospace"
android:text="Nome"
android:textAlignment="textStart"
android:textColor="#android:color/holo_orange_dark"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.093"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.251" />
<EditText
android:id="#+id/editTextMail"
android:layout_width="306dp"
android:layout_height="50dp"
android:ems="10"
android:fontFamily="monospace"
android:inputType="textEmailAddress"
android:textColor="#android:color/background_light"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3"
app:layout_constraintVertical_bias="0.0" />
<EditText
android:id="#+id/editTextCognome"
android:layout_width="306dp"
android:layout_height="50dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editTextNome"
app:layout_constraintVertical_bias="0.17" />
<EditText
android:id="#+id/editTextNome"
android:layout_width="306dp"
android:layout_height="50dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="#+id/textView4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView5"
app:layout_constraintVertical_bias="0.0" />
<EditText
android:id="#+id/editTextTessera"
android:layout_width="306dp"
android:layout_height="50dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView6"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="#+id/button"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="monospace"
android:text="Avanti"
android:textAlignment="center"
android:textColor="#android:color/holo_orange_dark"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editTextTessera"
app:layout_constraintVertical_bias="0.487" />
</android.support.constraint.ConstraintLayout>
ACTIVITY PAGE2
package com.example.principale.designazioni;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class Page2 extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page2);
final TextView nome = (TextView) findViewById(R.id.textViewPage2);
Bundle bundle = this.getIntent().getExtras();
nome.setText(bundle.getString("nome"));
}
}
XML ACTIVITY PAGE2
<?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"
tools:context=".Page2">
<TextView
android:id="#+id/textViewPage2"
android:layout_width="180dp"
android:layout_height="47dp"
android:fontFamily="monospace"
android:text="TextView"
android:textAlignment="center"
android:textColor="#android:color/holo_orange_dark"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
ANDROID MANIFEST
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.principale.designazioni">
<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=".Page1" />
<activity android:name=".Page2"></activity>
</application>
</manifest>
STACK TRACE
08-24 10:21:07.370 6819-6819/com.example.principale.designazioni E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.principale.designazioni, PID: 6819
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.principale.designazioni/com.example.principale.designazioni.Page1}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.example.principale.designazioni.Page1.onCreate(Page1.java:30)
at android.app.Activity.performCreate(Activity.java:7372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302) 
at android.app.ActivityThread.-wrap12(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891) 
at android.os.Handler.dispatchMessage(Handler.java:108) 
at android.os.Looper.loop(Looper.java:166) 
at android.app.ActivityThread.main(ActivityThread.java:7425) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) 
Change this line in Page1.java
from
Button avanti = (Button) findViewById(R.id.buttInvia);
to
Button avanti = (Button) findViewById(R.id.button);

How to fix android app crash issues?

My project on android studio is running fine on few phones and emulators but crashes on many phones. I have a Main_Activity and clicking on login takes to a second activity. I am sharing the java files and xml files of both activities along with android manifest.
Main Activity Java file
package club.pithynews.iitbhilai_pithy;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText username;
private EditText password;
private Button login_button;
#Override
protected void onCreate(Bundle savedInstanceState) {
java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LoginButton();
}
public void LoginButton() {
username = (EditText) findViewById(R.id.editText);
password = (EditText) findViewById(R.id.editText2);
login_button = (Button) findViewById(R.id.button);
login_button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
if ((username.getText().toString().equals("user"))&&(password.getText().toString().equals("pass"))) {
Intent intent = new Intent("club.pithynews.iitbhilai_pithy.User");
startActivity(intent);
}
}
}
);
}
}
Main Activity XML file
<?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="#drawable/back_login"
tools:context="club.pithynews.iitbhilai_pithy.MainActivity">
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#11000000"
android:ems="10"
android:hint="#string/user_name"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.78"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.53" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#11000000"
android:ems="10"
android:hint="#string/password"
android:inputType="textPassword"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.78"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.64" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:maxHeight="30dp"
android:maxWidth="30dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.05"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.53"
app:srcCompat="#drawable/user1"
android:contentDescription="#string/todo" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:maxHeight="30dp"
android:maxWidth="30dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.06"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.64"
app:srcCompat="#drawable/lock1"
android:contentDescription="#string/todo" />
<Button
android:id="#+id/button"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/back_login"
android:text="#string/login"
android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.79" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="233dp"
android:layout_height="227dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="1dp"
android:layout_marginStart="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.43"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.057"
app:srcCompat="#drawable/logoiit"
android:contentDescription="#string/todo" />
</android.support.constraint.ConstraintLayout >
Second Activity Java file
package club.pithynews.iitbhilai_pithy;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class User extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user);
}
}
Second Activity XML file
<?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"
android:background="#drawable/white"
tools:context="club.pithynews.iitbhilai_pithy.User">
<ImageButton
android:id="#+id/imageButton_emergency3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="80dp"
android:maxHeight="100dp"
android:scaleType="fitCenter"
android:layout_marginLeft="270dp"
android:layout_marginTop="350dp"
android:src="#drawable/emergency3"
android:background="#null"
android:layout_marginStart="270dp"
android:contentDescription="#string/todo13" />
<ImageButton
android:id="#+id/imageButton_feedback1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="125dp"
android:maxHeight="100dp"
android:scaleType="fitCenter"
android:layout_marginLeft="265dp"
android:layout_marginTop="445dp"
android:src="#drawable/feedback1"
android:background="#null"
android:layout_marginStart="265dp"
android:contentDescription="#string/todo12" />
<ImageButton
android:id="#+id/imageButton_aboutus1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="125dp"
android:maxHeight="500dp"
android:scaleType="fitCenter"
android:layout_marginLeft="125dp"
android:layout_marginTop="455dp"
android:src="#drawable/aboutus1"
android:background="#null"
android:layout_marginStart="125dp"
android:contentDescription="#string/todo11" />
<ImageButton
android:id="#+id/imageButton_campusmap1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="125dp"
android:maxHeight="80dp"
android:scaleType="fitCenter"
android:layout_marginLeft="20dp"
android:layout_marginTop="455dp"
android:src="#drawable/campusmap1"
android:background="#null"
android:layout_marginStart="20dp"
android:contentDescription="#string/todo10" />
<ImageButton
android:id="#+id/imageButton_adminstrators"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="100dp"
android:maxHeight="500dp"
android:scaleType="fitCenter"
android:layout_marginLeft="140dp"
android:layout_marginTop="350dp"
android:src="#drawable/adminstrators"
android:background="#null"
android:layout_marginStart="140dp"
android:contentDescription="#string/todo9" />
<ImageButton
android:id="#+id/imageButton_fnr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="350dp"
android:adjustViewBounds="true"
android:background="#null"
android:contentDescription="#string/fee_and_registration"
android:maxHeight="200dp"
android:maxWidth="75dp"
android:scaleType="fitCenter"
android:src="#drawable/fnr"
android:layout_marginStart="25dp" />
<ImageButton
android:id="#+id/imageButton_clubs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="265dp"
android:layout_marginTop="220dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/clubs"
android:layout_marginStart="265dp"
android:contentDescription="#string/todo8" />
<ImageButton
android:id="#+id/imageButton_studdata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="135dp"
android:layout_marginTop="220dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/studdata"
android:layout_marginStart="135dp"
android:contentDescription="#string/todo7" />
<ImageButton
android:id="#+id/imageButton_bus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="220dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/bus"
android:layout_marginStart="15dp"
android:contentDescription="#string/todo6" />
<ImageButton
android:id="#+id/imageButton_mess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="265dp"
android:layout_marginTop="100dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/mess"
android:layout_marginStart="265dp"
android:contentDescription="#string/todo5" />
<ImageButton
android:id="#+id/imageButton_faculty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="135dp"
android:layout_marginTop="100dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/faculty"
android:layout_marginStart="135dp"
android:contentDescription="#string/todo4" />
<ImageButton
android:id="#+id/imageButton_academics"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="100dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/academics"
android:layout_marginStart="15dp"
android:contentDescription="#string/todo3" />
<ImageButton
android:id="#+id/imageButton_newsletter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="265dp"
android:layout_marginTop="0dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/news"
android:layout_marginStart="265dp"
android:contentDescription="#string/todo" />
<ImageButton
android:id="#+id/imageButton_events"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="135dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/events"
android:layout_marginStart="135dp"
android:contentDescription="#string/todo1" />
<ImageButton
android:id="#+id/imageButton_today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="0dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/today"
android:layout_marginStart="15dp"
android:contentDescription="#string/todo2" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_alignEnd="#+id/imageButton_emergency3"
android:layout_alignRight="#+id/imageButton_emergency3"
android:text="#string/textview5"
android:textColor="#color/colorPrimaryDark"
android:visibility="visible"
tools:text=" Emergency " />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView3"
android:layout_alignBottom="#+id/textView3"
android:layout_alignEnd="#+id/imageButton_adminstrators"
android:layout_alignRight="#+id/imageButton_adminstrators"
android:text="#string/administrators"
android:textColor="#color/colorPrimaryDark" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton_bus"
android:layout_alignStart="#+id/imageButton_bus"
android:layout_below="#+id/imageButton_fnr"
android:text="#string/textview4"
android:textColor="#color/colorPrimaryDark"
tools:text=" Fees and\n Registration" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_alignStart="#+id/textView3"
android:layout_below="#+id/imageButton_campusmap1"
android:text="#string/textview3"
tools:text=" Campus Map"
android:textColor="#color/colorPrimaryDark"/>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton_adminstrators"
android:layout_alignStart="#+id/imageButton_adminstrators"
android:layout_below="#+id/imageButton_campusmap1"
android:text="#string/textview2"
tools:text=" About Us"
android:textColor="#color/colorPrimaryDark"/>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton_feedback1"
android:layout_alignStart="#+id/imageButton_feedback1"
android:layout_alignTop="#+id/textView5"
android:text="#string/textview1"
tools:text=" Feedback"
android:textColor="#color/colorPrimaryDark"/>
</RelativeLayout>
Android Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="club.pithynews.iitbhilai_pithy">
<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=".User">
<intent-filter>
<action android:name="club.pithynews.iitbhilai_pithy.User" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
</resources>
Debug Report when app crashes
W/System: ClassLoader referenced unknown path: /data/app/club.pithynews.iitbhilai_pithy-1/lib/arm
I/InstantRun: starting instant run server: is main process
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
D/TextView: setTypeface with style : 0
D/TextView: setTypeface with style : 0
W/ResourceType: Failure getting entry for 0x7f06005a (t=5 e=90) (error -75)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: club.pithynews.iitbhilai_pithy, PID: 16468
java.lang.RuntimeException: Unable to start activity ComponentInfo{club.pithynews.iitbhilai_pithy/club.pithynews.iitbhilai_pithy.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.constraint.ConstraintLayout
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.constraint.ConstraintLayout
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.constraint.ConstraintLayout
at android.app.Activity.performCreate(Activity.java:6904) 
at a
at android.app.ActivityThread.main(ActivityThread.java:7331) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: android.content.res.Resources$NotFoundException: Resource "club.pithynews.iitbhilai_pithy:drawable/back_login" (7f06005a) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f06005a a=-1 r=0x7f06005a}
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:7331) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Error is self explanatory. You're trying to load an image that is too big.
Canvas: trying to draw too large(111300000bytes) bitmap.
One of your drawable source that you set on your ImageButton or ImageView is too big. You can:
Scale image manually
Perform scaling in code and set the image afterwards
java.lang.RuntimeException: Canvas: trying to draw too large(111300000bytes) bitmap.
As you can see, you are trying to display an image that is too large. Check the size of the included bitmap resources.
you are displaying an image of size 111.3 mb which is too large to handle you need to compress and scale to some smaller version before displaying.
here you can scale your image.
Bitmap scaled = Bitmap.createScaledBitmap(originalBitmap, 120, 120, false);
more here
and compress using
ByteArrayOutputStream out = new ByteArrayOutputStream();
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 85, out);
see more here

java.lang.Throwable: setStateLocked

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>

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