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

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);

Related

Android java, Side drawer menu is showing up whenever the app is launched and the app is getting crashed on closing the menu

java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
at com.example.books.MainActivity.onOptionsItemSelected(MainActivity.java:245)
The terminal shows that the error is with the onOptionsItemSelected function
I have referred many StackOverflow posts regarding errors with side navigation drawer but I couldn't find the solution
Logcat
2022-05-08 17:13:15.175 867-867/com.example.books E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.books, PID: 867
java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
at androidx.drawerlayout.widget.DrawerLayout.openDrawer(DrawerLayout.java:1736)
at androidx.drawerlayout.widget.DrawerLayout.openDrawer(DrawerLayout.java:1722)
at androidx.appcompat.app.ActionBarDrawerToggle.toggle(ActionBarDrawerToggle.java:287)
androidx.appcompat.app.ActionBarDrawerToggle.onOptionsItemSelected(MainActivity.java:245)
at com.example.books.MainActivity.onOptionsItemSelected(MainActivity.java:245)
at android.app.Activity.onMenuItemSelected(Activity.java:4324)
at androidx.fragment.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:352)
at androidx.appcompat.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:264)
at androidx.appcompat.view.WindowCallbackWrapper.onMenuItemSelected
at androidx.appcompat.widget.ToolbarWidgetWrapper$1.onClick(ToolbarWidgetWrapper.java:188)
at android.view.View.performClick(View.java:8160)
at android.view.View.performClickInternal(View.java:8137)
at android.view.View.access$3700(View.java:888)
at android.view.View$PerformClick.run(View.java:30250)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
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_gravity="left"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/dl">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<SearchView
android:id="#+id/searchView"
android:layout_width="277dp"
android:layout_height="34dp"
android:layout_alignParentTop="true"
android:background="#drawable/bg_white_rounded"
android:iconifiedByDefault="false"
android:queryHint="Search book,title,author, etc.."
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.119"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.035"
app:queryBackground="#drawable/bg_white_rounded"
app:submitBackground="#drawable/bg_white_rounded"
tools:ignore="MissingConstraints">
</SearchView>
<androidx.cardview.widget.CardView
android:id="#+id/cardView2"
android:layout_width="96dp"
android:layout_height="100dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardMaxElevation="10dp"
app:contentPadding="#dimen/cardview_default_elevation"
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.131">
<ImageView
android:id="#+id/idIVCourseImage5"
android:layout_marginLeft="10dp"
android:layout_width="76dp"
android:layout_height="100dp"
android:src="#drawable/bookdonation" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardView"
android:layout_width="96dp"
android:layout_height="100dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardMaxElevation="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.136"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.131">
<ImageView
android:id="#+id/idIVCourseImage1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:clickable="true"
android:src="#drawable/onlinepurchase" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardView3"
android:layout_width="96dp"
android:layout_height="100dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
app:cardMaxElevation="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.865"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.131" >
<ImageView
android:id="#+id/idIVCourseImage2"
android:layout_marginTop="10dp"
android:layout_width="96dp"
android:layout_height="80dp"
android:src="#drawable/prouddonars" />
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FICTION AND NON-FICTION BOOKS"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.115"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.519" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/idRVCourse"
android:layout_width="403dp"
android:layout_height="333dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.961"
tools:ignore="MissingConstraints">
</androidx.recyclerview.widget.RecyclerView>
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/inter_medium"
android:text="Purchase books"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.122"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.276" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/inter_medium"
android:text="Donate books"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.276"
android:clickable="true"/>
<TextView
android:id="#+id/textView11"
android:layout_width="89dp"
android:layout_height="17dp"
android:fontFamily="#font/inter_medium"
android:text="Proud donars"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.869"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.275" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">
</LinearLayout>
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="407dp"
android:layout_height="148dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.401"
tools:ignore="MissingConstraints">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="120dp"
android:orientation="horizontal">
<androidx.cardview.widget.CardView
android:layout_width="408dp"
android:layout_height="136dp"
android:elevation="10dp"
app:cardCornerRadius="8dp"
app:cardMaxElevation="10dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<ImageView
android:layout_width="99dp"
android:layout_height="99dp"
android:src="#drawable/medical"></ImageView>
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginLeft="110dp"
android:layout_marginTop="15dp"
android:text="MEDICAL HEALTH AND SCIENCE BOOKS"></TextView>
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="110dp"
android:layout_marginTop="50dp"
android:text="Biochemistry| Physiotherapy | Phathalogy"></TextView>
<Button
android:id="#+id/buttonmed"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="55dp"
android:layout_marginRight="10dp"
android:fontFamily="#font/inter"
android:text="Order "
android:textAllCaps="false"
android:textSize="10sp" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="408dp"
android:layout_height="136dp"
android:layout_marginBottom="10dp"
android:elevation="10dp"
app:cardCornerRadius="8dp"
app:cardMaxElevation="10dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<ImageView
android:layout_width="96dp"
android:layout_height="wrap_content"
android:src="#drawable/fictionandnonfiction"></ImageView>
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginLeft="110dp"
android:layout_marginTop="15dp"
android:text="EXPLORE THE WIDE RANGE OF FICTION AND NON FICTION"></TextView>
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="110dp"
android:layout_marginTop="50dp"
android:text="Science Fiction| Short stories | Teens"></TextView>
<Button
android:id="#+id/buttoneng"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="55dp"
android:layout_marginRight="10dp"
android:fontFamily="#font/inter"
android:text="Order"
android:textAllCaps="false"
android:textSize="10sp" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="408dp"
android:layout_height="136dp"
android:elevation="10dp"
app:cardCornerRadius="8dp"
app:cardMaxElevation="10dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<ImageView
android:layout_width="96dp"
android:layout_height="wrap_content"
android:src="#drawable/ncert"></ImageView>
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginLeft="110dp"
android:layout_marginTop="15dp"
android:text="NCERT BOOKS FOR CLASS 1-12"></TextView>
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="110dp"
android:layout_marginTop="50dp"
android:text="Physics| Chemistry | Mathematics"></TextView>
<Button
android:id="#+id/buttonfiction"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="55dp"
android:layout_marginRight="10dp"
android:fontFamily="#font/inter"
android:text="Order"
android:textAllCaps="false"
android:textSize="10sp" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="408dp"
android:layout_height="136dp"
android:elevation="10dp"
app:cardCornerRadius="8dp"
app:cardMaxElevation="10dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<ImageView
android:layout_width="96dp"
android:layout_height="wrap_content"
android:src="#drawable/competative"></ImageView>
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginLeft="110dp"
android:layout_marginTop="15dp"
android:text=" WIDE RANGE OF AVAILABLE COMPITATIVE EXAM BOOKS"></TextView>
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="110dp"
android:layout_marginTop="50dp"
android:text="Banking| UPSC| SSC"></TextView>
<Button
android:id="#+id/buttonfinance"
android:layout_width="77dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="55dp"
android:layout_marginRight="10dp"
android:fontFamily="#font/inter"
android:text="Order"
android:textAllCaps="false"
android:textSize="10sp" />
</androidx.cardview.widget.CardView>
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.777"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.048"
app:srcCompat="#drawable/ic_favorite" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="36dp"
android:layout_height="29dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.045"
app:srcCompat="#drawable/cart1" />
<ImageView
android:id="#+id/imageView8"
android:layout_width="32dp"
android:layout_height="27dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/linearLayout"
app:layout_constraintHorizontal_bias="0.889"
app:layout_constraintStart_toStartOf="#+id/linearLayout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.048"
app:srcCompat="#drawable/ic_location" />
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/idnav_bar"
android:layout_gravity="left"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header"
app:menu="#menu/drawer_menu"
tools:ignore="InvalidId,MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout>
Mainactivity.java
package com.example.books;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.widget.Toolbar;
import com.google.android.material.navigation.NavigationView;
import com.synnapps.carouselview.CarouselView;
import com.synnapps.carouselview.ImageClickListener;
import com.synnapps.carouselview.ImageListener;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import android.view.MenuItem.OnMenuItemClickListener;
import java.util.Objects;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {
private Button button;
private Button medbutton;
private RecyclerView courseRV;
public DrawerLayout dl;
private Toolbar toolbar;
public ActionBarDrawerToggle abdt;
public TextView TVdonars;
public TextView TVdonatebooks;
public TextView TVpurchasebooks;
public ImageView wishlistimg;
private ArrayList<CourseModel> courseModelArrayList;
private int[] mImages = new int[]{
R.drawable.academic, R.drawable.engineering, R.drawable.medical, R.drawable.fiction
};
private String[] mImagesTitle = new String[]{
"Academic", "Engineering", "Medical", "Fiction"
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setTitle("Classic Books Donar");
medbutton = findViewById(R.id.buttonmed);
wishlistimg = findViewById(R.id.imageView5);
//button = (Button) findViewById(R.id.button2);
courseRV = findViewById(R.id.idRVCourse);
TVpurchasebooks = findViewById(R.id.textView9);
TVdonatebooks = findViewById(R.id.textView10);
TVdonars = findViewById(R.id.textView11);
TVdonatebooks.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, Register.class);
startActivity(intent);
}
});
TVdonars.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, Prouddonars.class);
startActivity(intent);
}
});
TVpurchasebooks.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, Purchasebooks.class);
startActivity(intent);
}
});
final NavigationView nav_view = (NavigationView) findViewById(R.id.idnav_bar);
nav_view.setNavigationItemSelectedListener(new
NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
int id = item.getItemId();
if (id == R.id.select_catogery) {
Toast.makeText(MainActivity.this, "Select Catogery",
Toast.LENGTH_SHORT).show();
}
if (id == R.id.engineering) {
Toast.makeText(MainActivity.this, "Engineering", Toast.LENGTH_SHORT).show();
}
if (id == R.id.medical) {
Toast.makeText(MainActivity.this, "Medical", Toast.LENGTH_SHORT).show();
}
return true;
}
});
dl = (DrawerLayout) findViewById(R.id.dl);
abdt = new ActionBarDrawerToggle(this, dl, toolbar, R.string.open, R.string.close);
abdt.setDrawerIndicatorEnabled(true);
//Toolbar toolbar = findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
dl.addDrawerListener(abdt);
abdt.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
courseModelArrayList = new ArrayList<>();
courseModelArrayList.add(new CourseModel("Design of Machine Elements, Fourth Edition", "V
B Bhandari", R.drawable.designofmachineelements));
courseModelArrayList.add(new CourseModel("Fluid Mechanics, Sixth Edition", "Munsun,
Okilshi,Huebsch & Rothmayer", R.drawable.fluidmechanics));
courseModelArrayList.add(new CourseModel("Fundamentals of Thermodynamics", "Claus
Borgnakke & Richard E Sonntag", R.drawable.thermodynamics));
courseModelArrayList.add(new CourseModel("Shigley's Mechanical Engineering Design",
"Richard G Budynas & JJ Keith Nisbett", R.drawable.mechanicalengineeringdesign));
courseModelArrayList.add(new CourseModel("Atlas of Human Anatomy, Seventh Edition", "Frank
H. Netter, MD ", R.drawable.atlasofhumananatomy));
courseModelArrayList.add(new CourseModel("Data structures and algorithms", " Alfred V.Aho,
John E.Hopcroft, Jeffrey D.Ullman", R.drawable.datastructures));
courseModelArrayList.add(new CourseModel("Textbook of Clinical Neuroanatomy, Third
Edition", "Vishram Singh ", R.drawable.clinicalneuroanatomy));
// we are initializing our adapter class and passing our arraylist to it.
CourseAdapter courseAdapter = new CourseAdapter(this, courseModelArrayList);
// below line is for setting a layout manager for our recycler view.
// here we are creating vertical list so we will provide orientation as vertical
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this,
LinearLayoutManager.VERTICAL, false);
// in below two lines we are setting layoutmanager and adapter to our recycler view.
courseRV.setLayoutManager(linearLayoutManager);
courseRV.setAdapter(courseAdapter);
medbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, Medical.class);
startActivity(intent);
}
});
wishlistimg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, Wishlist.class);
startActivity(intent);
}
});
#Override
public boolean onOptionsItemSelected(MenuItem item){
int id = item.getItemId();
if (abdt.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference.EditText is initialized

I got The Error while making an Instagram clone
I have initialized the EditTexts
I don't Know Why I get this
I cant add Code so will add it in comment
My Error
My Code
My Java Code
package com.example.instagram;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.SignUpCallback;
import com.shashank.sony.fancytoastlib.FancyToast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button btnSignUp,btnLogIn;
private EditText edtUsername,edtPassword,edtEmail;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Sign Up");
setContentView(R.layout.activity_main);
edtEmail = findViewById(R.id.edtEmailAdressSignUp);
edtUsername = findViewById(R.id.edtUserNameSignUp);
edtPassword = findViewById(R.id.edtPasswordLogin);
btnSignUp = findViewById(R.id.btnSignUp);
btnLogIn = findViewById(R.id.btnLogIn);
btnLogIn.setOnClickListener(this);
btnSignUp.setOnClickListener(this);
}
#Override
public void onClick(View view) {
switch (view.getId()){
case R.id.btnSignUp:
final ParseUser appUser = new ParseUser();
appUser.setEmail(edtEmail.getText().toString());
appUser.setUsername(edtUsername.getText().toString());
appUser.setPassword(edtPassword.getText().toString());
appUser.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
if (e == null){
FancyToast.makeText(getApplicationContext(),appUser.getUsername() + " is Signed Up",FancyToast.LENGTH_LONG,FancyToast.SUCCESS,true);
}
else{
FancyToast.makeText(getApplicationContext(),"Something went wrong: " + e,FancyToast.LENGTH_LONG,FancyToast.WARNING,true);
}
}
});
break;
case R.id.btnLoginA:
break;
}
}
}
My XML Code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F05644"
tools:context=".MainActivity">
<Button
android:id="#+id/btnSignUp"
android:layout_width="404dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginBottom="34dp"
android:background="#4568FC"
android:gravity="center_horizontal"
android:text="Sign UP"
android:textColor="#fff"
android:textSize="36sp"
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.85" />
<EditText
android:id="#+id/edtEmailAdressSignUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="101dp"
android:layout_marginEnd="101dp"
android:layout_marginBottom="40dp"
android:ems="10"
android:hint="Enter Your Email Adress"
android:inputType="textEmailAddress"
android:textColor="#fff"
android:textColorHint="#fff"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="#+id/btnSignUp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:background="#F05644"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/instagram" />
<Button
android:id="#+id/btnLogIn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="41dp"
android:layout_marginBottom="55dp"
android:background="#98BB00"
android:text="Log In"
android:textColor="#fff"
android:textSize="36sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/btnSignUp"
app:layout_constraintVertical_bias="1.0" />
<EditText
android:id="#+id/edtUserNameSignUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Your User Name"
android:inputType="textPersonName"
android:textColor="#FFFFFF"
android:textColorHint="#FFFFFF"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView2" />
<EditText
android:id="#+id/edtPasswordSignUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="89dp"
android:layout_marginTop="61dp"
android:layout_marginEnd="112dp"
android:layout_marginBottom="34dp"
android:ems="10"
android:hint="Enter Your Password"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#FFFFFF"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="#+id/edtEmailAdressSignUp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.421"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edtUserNameSignUp"
app:layout_constraintVertical_bias="0.812" />
</androidx.constraintlayout.widget.ConstraintLayout>
My Log
2020-07-15 12:34:15.118 10378-10378/? E/ample.instagra: Unknown bits set in runtime_flags: 0x8000
2020-07-15 12:35:16.066 10378-10378/com.example.instagram E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.instagram, PID: 10378
java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at com.example.instagram.MainActivity.onClick(MainActivity.java:41)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Your password edit text id is wrong
edtPassword = findViewById(R.id.edtPasswordSignUp);

Getting Null Pointer Exception when trying to .setText() for a SharedPreferences String

I am quite new to android programming so thanks advance for helping.
On button click, I am trying store the boolean values and a string value into SharedPreferences. After storing it, it will update the mainActivty.xml page. However, after many tries and hours of looking up, i cannot seem to find a way to get rid of the Null Pointer Exception when trying to .setText() the string value. Any help will be much appreciated, thanks
I have tried to create an inflater since some of the issue arise with the view not getting inflated. I have also tried to reassign the location for my textView initialization but to no avail.
This is the SettingPage code:
package com.example.sleep;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class SettingPage extends AppCompatActivity{
public EditText setMinBar;
public Button setTimeEnterButton;
public Switch musicYesSwitch, soundYesSwitch;
public String SP = "New SP", timeStr = "nothing", finalTimeStr = "nil";
public boolean musicYes, soundYes;
public TextView minLeftTV, timerEndsTV;
public SharedPreferences varAcrossApp;
public SharedPreferences.Editor varEditor;
#Override //Creating the setting page
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settingpage);
setMinBar = findViewById(R.id.numMinsBar);
setTimeEnterButton = findViewById(R.id.setTimeButton);
musicYesSwitch = findViewById(R.id.musicSwitch);
soundYesSwitch = findViewById(R.id.soundSwitch);
timerEndsTV = findViewById(R.id.timerEndsTV);
minLeftTV = (TextView) findViewById(R.id.minsLeftDisplay);
varAcrossApp = PreferenceManager.getDefaultSharedPreferences(this);
setTimeEnterButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
saveData();
loadData();
updateView();
}
});
}
public void saveData(){ //Declaring method saveData
varEditor = varAcrossApp.edit();
varEditor.putString(timeStr, setMinBar.getText().toString());
varEditor.putBoolean("mYes", musicYesSwitch.isChecked());
varEditor.putBoolean("sYes", soundYesSwitch.isChecked());
varEditor.apply();
}
public void loadData(){ //Declaring method loadData
finalTimeStr = varAcrossApp.getString(timeStr, "0");
musicYes = varAcrossApp.getBoolean("mYes", false);
soundYes = varAcrossApp.getBoolean("sYes", false);
Toast.makeText(getApplicationContext(), "Duration set" +
finalTimeStr, Toast.LENGTH_SHORT).show();
}
public void updateView() {
Log.d(SP, "Time is " + finalTimeStr);
minLeftTV.setText(finalTimeStr);
if (musicYes && soundYes) {
timerEndsTV.setText("-Turn off music /n-Change sound profile to
'Sound'");
} else if (soundYes = true) {
timerEndsTV.setText("-Change sound profile to 'Sound'");
} else if (musicYes = true) {
timerEndsTV.setText("-Turn off music");
} else {
timerEndsTV.setText("-Do nothing");
}
}
}
This is the Homepage.xml page
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/homepage"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<TextView
android:id="#+id/timeLeft"
android:layout_width="191dp"
android:layout_height="49dp"
android:layout_marginStart="146dp"
android:layout_marginTop="70dp"
android:layout_marginEnd="147dp"
android:fontFamily="#font/bree_serif"
android:text="#string/text_header"
android:textAlignment="center"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/timeLeftNum"
android:layout_width="84dp"
android:layout_height="52dp"
android:layout_marginTop="143dp"
android:layout_marginEnd="103dp"
android:layout_marginBottom="138dp"
android:fontFamily="#font/bree_serif"
android:text="#string/text_timeUnit"
android:textAlignment="center"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/timerEndsTV"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/timeLeft" />
<TextView
android:id="#+id/whenTimerEnd"
android:layout_width="132dp"
android:layout_height="20dp"
android:layout_marginStart="54dp"
android:layout_marginEnd="253dp"
android:layout_marginBottom="12dp"
android:fontFamily="#font/bree_serif"
android:text="#string/text_whenTimerEnd"
android:textAlignment="viewStart"
app:layout_constraintBottom_toTopOf="#+id/timerEndsTV"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/timerEndsTV"
android:layout_width="299dp"
android:layout_height="54dp"
android:layout_marginStart="54dp"
android:layout_marginEnd="58dp"
android:layout_marginBottom="114dp"
android:fontFamily="#font/bree_serif"
android:text="TextView"
app:layout_constraintBottom_toTopOf="#+id/startButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/startButton"
android:layout_width="382dp"
android:layout_height="52dp"
android:layout_marginStart="13dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:fontFamily="#font/bree_serif"
android:text="#string/text_startButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/minsLeftDisplay"
android:layout_width="155dp"
android:layout_height="144dp"
android:layout_marginStart="68dp"
android:layout_marginTop="56dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="107dp"
android:text="#string/numberInDisplay"
android:textAlignment="textEnd"
android:textSize="125sp"
app:layout_constraintBottom_toTopOf="#+id/whenTimerEnd"
app:layout_constraintEnd_toStartOf="#+id/timeLeftNum"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/timeLeft" />
</androidx.constraintlayout.widget.ConstraintLayout>
This is the SettingPage.xml page:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/settingPageConstrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/inputLayout"
android:layout_width="299dp"
android:layout_height="81dp"
android:layout_marginStart="56dp"
android:layout_marginEnd="56dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/TextboxDurationMins">
<EditText
android:id="#+id/numMinsBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<Button
android:id="#+id/setTimeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/bree_serif"
android:text="#string/setTimeButton" />
</LinearLayout>
<LinearLayout
android:id="#+id/switchesLayout"
android:layout_width="64dp"
android:layout_height="69dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="218dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<Switch
android:id="#+id/musicSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Switch
android:id="#+id/soundSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/textBoxLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginEnd="69dp"
android:layout_marginBottom="230dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/switchesLayout"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="#+id/turnOffMusics"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/bree_serif"
android:text="#string/offMusic"
android:textAlignment="textStart"
android:textSize="18sp" />
<TextView
android:id="#+id/onSound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/bree_serif"
android:text="#string/onSound"
android:textAlignment="textStart"
android:textSize="18sp" />
</LinearLayout>
<TextView
android:id="#+id/TextboxDurationMins"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="176dp"
android:layout_marginEnd="120dp"
android:fontFamily="#font/bree_serif"
android:text="#string/setDurationMins"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
This is the error code:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sleep, PID: 16835
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.TextView.setText(java.lang.CharSequence)' on a null object
reference
at com.example.sleep.SettingPage.updateView(SettingPage.java:82)
at com.example.sleep.SettingPage$1.onClick(SettingPage.java:53)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3400(View.java:801)
at android.view.View$PerformClick.run(View.java:27301)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7319)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
The issue is related to minLeftTV.setText(finalTimeStr);
You are creating an instance by calling
minLeftTV = (TextView) findViewById(R.id.minsLeftDisplay);
but your xml layout does not have any view with that id - #+id/minsLeftDisplay and hence minLeftTV is null and you are getting a null pointer exception.
You have a TextView with id => #+id/TextboxDurationMins which is the view you want to set the text to (I am assuming). Change the id in layout or your activity code.

Crashes probably due to bad activity layout

I've been developing an application and it has been working good until I added a LinearLayout (id = 'toolbar') and some functions in that activity's corresponding Java file. Here are my codes:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.com.myapplication">
<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=".EditPhotoActivity"
android:parentActivityName=".MainActivity">
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>
MainActivty is working good and I don't think the problem is in it. Please let me know if you want me add its code.
EditPhotoActivity.java
package com.example.com.myapplication;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;
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.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
import java.io.IOException;
public class EditPhotoActivity extends AppCompatActivity {
public ImageView image_view = findViewById(R.id.image_display) ;
public boolean toolbar_is_open = false ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_photo);
ImageView imageView = findViewById(R.id.image_display);
Intent intent = getIntent();
Uri content;
if(intent.getStringExtra(MainActivity.DATA_TYPE).equals("Uri")) {
Bundle bundle = intent.getExtras();
if(bundle != null) {
content = (Uri) bundle.get(MainActivity.IMAGE_KEY);
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), content);
imageView.setImageBitmap(bitmap);
} catch(IOException e) {
e.printStackTrace();
Toast.makeText(this, "Failed to fetch image data!", Toast.LENGTH_LONG).show() ;
}
}
} else if(intent.getStringExtra(MainActivity.DATA_TYPE).equals("Bundle")) {
Bundle bundle = intent.getBundleExtra(MainActivity.IMAGE_KEY);
Bitmap bitmap = (Bitmap)bundle.get("data");
imageView.setImageBitmap(bitmap);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.publish_menu, menu);
return true ;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.share_button:
// Save the photo
break;
case R.id.save_button:
// Open Share Photo Activity
break;
}
return super.onOptionsItemSelected(item);
}
private void setToolbarState(boolean open) {
LinearLayout toolbar = findViewById(R.id.toolbar);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)toolbar.getLayoutParams();
params.height = open? 50 : 0;
toolbar.setLayoutParams(params);
toolbar_is_open = open ;
}
public void openRotateToolbar(View view) {
Button right = new Button(this), left = new Button(this);
right.setText(R.string.right); left.setText(R.string.left);
right.setBackgroundResource(R.drawable.custom_button);
left.setBackgroundResource(R.drawable.custom_button);
right.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View view) {
image_view.setRotation(90f);
}
});
left.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View view) {
image_view.setRotation(-90f);
}
});
if(!toolbar_is_open)
setToolbarState(true);
}
public void closeToolbar(View view) {
if(toolbar_is_open)
setToolbarState(false);
}
}
activity_edit_photo.xml
<?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="com.example.com.myapplication.EditPhotoActivity"
tools:layout_editor_absoluteY="81dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_display"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:background="#color/black"
android:padding="0dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="#+id/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_launcher_background"
tools:ignore="contentDescription" />
<LinearLayout
android:id="#+id/toolbar"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#111"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#+id/scrollView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/close"
android:background="#drawable/custom_button"
android:textColor="#fff"
android:onClick="closeToolbar" />
</LinearLayout>
<HorizontalScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/darkGrey"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/custom_button"
android:text="#string/add_sticker"
android:textColor="#fff"
android:textSize="12sp"
tools:ignore="ButtonStyle" />
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="-15dp"
android:background="#drawable/custom_button"
android:gravity="center"
android:text="#string/create_sticker"
android:textSize="12sp"
tools:ignore="ButtonStyle" />
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/custom_button"
android:gravity="center"
android:text="#string/cut_sticker"
android:textSize="12sp"
tools:ignore="ButtonStyle" />
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/custom_button"
android:gravity="center"
android:text="#string/apply_filter"
android:textSize="12sp"
tools:ignore="ButtonStyle" />
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/custom_button"
android:gravity="center"
android:text="#string/rotate"
android:textSize="12sp"
tools:ignore="ButtonStyle"
android:onClick="openRotateToolbar" />
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/custom_button"
android:gravity="center"
android:text="#string/flip"
android:textSize="12sp"
tools:ignore="ButtonStyle" />
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/custom_button"
android:gravity="center"
android:text="#string/crop"
android:textSize="12sp"
tools:ignore="ButtonStyle" />
</LinearLayout>
</HorizontalScrollView>
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
I am not getting any errors but when the app is transitioning to EditPhoto Activity it crashes. Please let me know if you need me to provide you with any other information.
Note: I can not post the logcat because I am not using ADB and I am not using a computer that is all mine (it's my family's) so I don't want to enable x-vt in BIOS and so I am not able to use an Emulator also. To test my app I build the apk then I install it on my phone.
I have found my mistake. I will let this answer here for anyone that comes into the same problem.
The line:
public ImageView image_view = findViewById(R.id.image_display) ;
causes NullPointerException because at the time the app is opening the activity it does not yet have all the view and id's. It gets them only when it calls onCreate so I replaced the line to
public ImageView image_view ;
and inside onCreate after the super.onCreate(savedInstanceState) and the setContentView(R.layout.activity_edit_photo) calls I added
image_view = findViewById(R.id.image_display) ;

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

Categories

Resources