i've seen some answers suggest that i should change to this line of code
android.support.v7.widget.GridLayout
or
androidx.gridlayout.widget.GridLayout
none work.
also importing as v7 and as androidx didnt work.
please help. it worked fine until now :(
thank you!
MainActivity:
package com.example.braindtrainer;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
GridLayout myGridLayout;
Button goButton;
TextView timeTextView;
TextView scoreTextView;
TextView questionTextView;
TextView notifyTextView;
public void goClick(View view){
Log.i("goButton","Pressed");
timeTextView.setVisibility(View.VISIBLE);
scoreTextView.setVisibility(View.VISIBLE);
questionTextView.setVisibility(View.VISIBLE);
notifyTextView.setVisibility(View.VISIBLE);
goButton.setVisibility(View.INVISIBLE);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myGridLayout = findViewById(R.id.myGridLayout);
goButton = findViewById(R.id.goButton);
timeTextView = findViewById(R.id.timerTextView);
scoreTextView = findViewById(R.id.scoreTextView);
questionTextView = findViewById(R.id.questionTextView);
notifyTextView = findViewById(R.id.notifyTextView);
}
}
Layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="#+id/goButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#B388FF"
android:onClick="goClick"
android:text="GO!"
android:textSize="70dp"
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" />
<androidx.gridlayout.widget.GridLayout
android:id="#+id/myGridLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="300dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="300dp"
android:visibility="invisible"
app:columnCount="2"
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"
app:rowCount="2">
<TextView
android:id="#+id/firstTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#991230C8"
android:tag="1"
android:text="567"
android:textColor="#000000"
android:textSize="100sp"
app:layout_column="0"
app:layout_row="0" />
<TextView
android:id="#+id/secondTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A9C62424"
android:tag="2"
android:text="567"
android:textColor="#000000"
android:textSize="100sp"
app:layout_column="1"
app:layout_row="0" />
<TextView
android:id="#+id/thirdTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#9A60E841"
android:tag="3"
android:text="567"
android:textColor="#000000"
android:textSize="100sp"
app:layout_column="0"
app:layout_row="1" />
<TextView
android:id="#+id/fourthTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#94CFBF30"
android:tag="4"
android:text="567"
android:textColor="#000000"
android:textSize="100sp"
app:layout_column="1"
app:layout_row="1" />
</androidx.gridlayout.widget.GridLayout>
<TextView
android:id="#+id/timerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:background="#EA80FC"
android:text="15 s"
android:textColor="#000000"
android:textSize="60sp"
android:visibility="invisible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/scoreTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:background="#FFAB40"
android:text="0/0"
android:textColor="#000000"
android:textSize="60dp"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/questionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="29dp"
android:layout_marginLeft="29dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="34dp"
android:layout_marginRight="34dp"
android:background="#3E3C1515"
android:text="4 + 6"
android:textColor="#000000"
android:textSize="50dp"
android:visibility="invisible"
app:layout_constraintEnd_toStartOf="#+id/scoreTextView"
app:layout_constraintStart_toEndOf="#+id/timerTextView"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/notifyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="39dp"
android:text="00000"
android:textColor="#000000"
android:textSize="50dp"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/myGridLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
Log
2020-03-22 18:22:13.472 7929-7929/com.example.braindtrainer E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.braindtrainer, PID: 7929
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.braindtrainer/com.example.braindtrainer.MainActivity}: java.lang.ClassCastException: androidx.gridlayout.widget.GridLayout cannot be cast to android.widget.GridLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassCastException: androidx.gridlayout.widget.GridLayout cannot be cast to android.widget.GridLayout
at com.example.braindtrainer.MainActivity.onCreate(MainActivity.java:36)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
From the crash log is says there is a class cast exception. You used the GridLayout from the androidx library in the xml whereas, you are trying to cast it to the GridLayout from the android library modules in your java class. Hence you are getting this exception. You need to use the same version for both of your layout xml and the java class.
You need to import the following in your Java class.
import androidx.gridlayout.widget.GridLayout
And remove the following
import android.widget.GridLayout;
Related
I'm a college student and still learning how to use Android Studio. Can anybody help me with this? It keeps crashing when I get to the press login and it sends me this error. It says that it's the DrawerLayout but I've been trying for a while now and for the life of me I couldn't find how to fix it.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.librolaneandroidportal, PID: 4986
java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY.
at androidx.drawerlayout.widget.DrawerLayout.onMeasure(DrawerLayout.java:1053)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:146)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:747)
at android.view.View.measure(View.java:25466)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3397)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2228)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2486)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1952)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8171)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
at android.view.Choreographer.doCallbacks(Choreographer.java:796)
at android.view.Choreographer.doFrame(Choreographer.java:731)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/Process: Sending signal. PID: 4986 SIG: 9
And here's the Java file
package com.example.librolaneandroidportal;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.appcompat.widget.Toolbar;
import com.google.android.material.navigation.NavigationView;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
//Variables
DrawerLayout drawerLayout;
NavigationView navigationView;
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Hooks
drawerLayout = findViewById(R.id.drawer_layout);
navigationView = findViewById(R.id.nav_view);
toolbar = findViewById(R.id.toolbar);
//Toolbar
setSupportActionBar(toolbar);
//Navigation Drawer Menu
navigationView.bringToFront();
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.nav_home);
}
#Override
public void onBackPressed() {
if(drawerLayout.isDrawerOpen(GravityCompat.START)){
drawerLayout.closeDrawer(GravityCompat.START);
}
else{
super.onBackPressed();
}
}
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.nav_home:
break;
case R.id.nav_opac:
Intent intent = new Intent(MainActivity.this, Opac.class);
startActivity(intent);
break;
case R.id.nav_qr:
Intent intent2 = new Intent(MainActivity.this, QRscanner.class);
startActivity(intent2);
break;
}
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}
}
and here is the layout that I made.
<?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:id="#+id/drawer_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity"
tools:openDrawer="start">
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/nav_view"
app:headerLayout="#layout/header"
app:menu="#menu/main_menu"
android:layout_gravity="start"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_background">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationIcon="#drawable/ic_baseline_menu_24" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="175dp"
android:background="#drawable/round_layouts"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="#+id/linearLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.cardview.widget.CardView
android:id="#+id/OPACbutton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:padding="10dp"
app:cardBackgroundColor="#color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/opacbtnimage"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
app:srcCompat="#drawable/opac_btnicon" />
<TextView
android:id="#+id/opacbtnlabel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/opacbtnimage"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:text="#string/OPAC_btn_text"
android:textColor="#color/white"
android:textSize="18sp"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/QRbutton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:padding="10dp"
app:cardBackgroundColor="#color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/qrbtnimage"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
app:srcCompat="#drawable/scanner_btnicon" />
<TextView
android:id="#+id/qrbtnlabel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/qrbtnimage"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:text="#string/QR_btn_text"
android:textColor="#color/white"
android:textSize="18sp"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/Reservebutton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:padding="10dp"
app:cardBackgroundColor="#color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/reservebtnimage"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
app:srcCompat="#drawable/opac_btnicon" />
<TextView
android:id="#+id/reservebtnlabel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/reservebtnimage"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:text="#string/Reserve_btn_text"
android:textColor="#color/white"
android:textSize="18sp"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="175dp"
android:background="#color/white"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent">
<androidx.cardview.widget.CardView
android:id="#+id/Favoritesbutton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="20dp"
android:layout_weight="1"
android:padding="10dp"
app:cardBackgroundColor="#color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/favoritesbtnimage"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
app:srcCompat="#drawable/opac_btnicon" />
<TextView
android:id="#+id/favoritesbtnlabel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/favoritesbtnimage"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:text="#string/Favorite_btn_text"
android:textColor="#color/white"
android:textSize="18sp"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/Notificationbutton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="20dp"
android:layout_weight="1"
android:padding="10dp"
app:cardBackgroundColor="#color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/notificationbtnimage"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
app:srcCompat="#drawable/opac_btnicon" />
<TextView
android:id="#+id/notificationbtnlabel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/notificationbtnimage"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:text="#string/Notifications_btn_text"
android:textColor="#color/white"
android:textSize="18sp"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/Feedbackbutton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:layout_weight="1"
android:padding="10dp"
app:cardBackgroundColor="#color/ocean_green"
app:cardCornerRadius="15dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/Feedbackbtnimage"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
app:srcCompat="#drawable/opac_btnicon" />
<TextView
android:id="#+id/Feedbackbtnlabel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/Feedbackbtnimage"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:text="#string/Feedback_btn_text"
android:textColor="#color/white"
android:textSize="18sp"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout>
Make DrawerLayout and NavigationViews height and width "match_parent". Hope it will work :)
Change DrawerLayout "layout_width" to "match_parent"
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);
Android terminal
I getting errors in homepage of my new app of helpline,I tried to check all but still not running please check and comment accordingly Please review
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.googlemaps, PID: 18785
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemaps/com.example.googlemaps.HomeActivity}: android.view.InflateException: Binary XML file line #38: Binary XML file line #38: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3121)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3264)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1955)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7078)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:974)
Caused by: android.view.InflateException: Binary XML file line #38: Binary XML file line #38: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #38: Error inflating class fragment
Caused by: java.lang.NullPointerException
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Fragment.instantiate(Fragment.java:524)
at android.app.FragmentContainer.instantiate(FragmentContainer.java:53)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3551)
at android.app.FragmentController.onCreateView(FragmentController.java:103)
at android.app.Activity.onCreateView(Activity.java:6445)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:338)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:819)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:902)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:863)
at android.view.LayoutInflater.inflate(LayoutInflater.java:554)
at android.view.LayoutInflater.inflate(LayoutInflater.java:461)
at android.view.LayoutInflater.inflate(LayoutInflater.java:383)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.example.googlemaps.HomeActivity.onCreate(HomeActivity.java:24)
at android.app.Activity.performCreate(Activity.java:7327)
at android.app.Activity.performCreate(Activity.java:7318)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1275)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3101)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3264)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1955)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7078)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:974)
xml file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="HomeActivity">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="125dp"
android:layout_marginTop="5dp"
android:text="Welcome! You are logged in"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText"
android:layout_marginStart="125dp" />
<TextView
android:id="#+id/texttitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="125dp"
android:layout_marginTop="25dp"
android:text="24x7 SECURITY HELPLINE"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText"
android:layout_marginStart="50dp" />
<fragment
android:id="#+id/home"
android:layout_height="match_parent"
android:layout_width="140dp"
android:layout_marginTop="80dp"
tools:context=".HomeActivity"
android:background="#FA8072" />
<ImageButton
android:id="#+id/imageButton"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_marginTop="80dp"
tools:src="#tools:sample/avatars"
tools:ignore="HardcodedText"
android:contentDescription="Profile Pic"/>
<Button
android:id="#+id/profile"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginTop="210dp"
android:text="Your Profile"
tools:ignore="HardcodedText"/>
<Button
android:id="#+id/complain"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginTop="250dp"
android:text="Complain"
tools:ignore="HardcodedText"/>
<Button
android:id="#+id/tips"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginTop="290dp"
android:text="Safety Tips"
tools:ignore="HardcodedText"/>
<Button
android:id="#+id/alerts"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginTop="330dp"
android:text="Alerts"
tools:ignore="HardcodedText"/>
<Button
android:id="#+id/emergency"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginTop="370dp"
android:text="emergency"
tools:ignore="HardcodedText"/>
<Button
android:id="#+id/nearby"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginTop="410dp"
android:text="NearBy"
tools:ignore="HardcodedText"/>
<Button
android:id="#+id/volunteer"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginTop="450dp"
android:text="Volunteer"
tools:ignore="HardcodedText"/>
<Button
android:id="#+id/logout"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:layout_marginTop="490dp"
android:text="Logout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2"
tools:ignore="HardcodedText"
android:layout_marginStart="1dp" />
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="170dp"
android:layout_marginLeft="170dp"
android:layout_marginTop="400dp"
android:shadowRadius="3"
android:textColor="#0000FF"
android:text="Location sharing"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/custom_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:layout_marginLeft="150dp"
android:background="#drawable/custom_button"
android:layout_marginStart="150dp" />
<Switch
android:id="#+id/switch_enable_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:layout_marginLeft="200dp"
android:layout_marginTop="350dp"
android:text="Panic Alert"
android:layout_marginStart="200dp"
tools:ignore="HardcodedText"/>
<TextView
android:id="#+id/textView3"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="225dp"
android:layout_marginLeft="210dp"
android:text="Panic Mode"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp"
tools:ignore="HardcodedText"
android:layout_marginStart="200dp" />
<Button
android:id="#+id/report"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="480dp"
android:layout_marginLeft="170dp"
android:text="Report"
android:textColor="#FF0000"
tools:ignore="HardcodedText"
android:layout_marginStart="180dp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="130dp"
android:layout_marginLeft="150dp"
tools:ignore="HardcodedText"
android:text="Create your panic alert button "
android:layout_marginStart="150dp" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="650dp"
android:layout_marginLeft="150dp"
tools:ignore="HardcodedText"
android:text="Feedback"
android:textColor="#FFA500"
android:layout_marginStart="150dp" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="650dp"
android:layout_marginLeft="280dp"
tools:ignore="HardcodedText"
android:text="Write to us"
android:textColor="#FFA500"
android:layout_marginStart="280dp" />
</FrameLayout>
java file
package com.example.googlemaps;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.firebase.auth.FirebaseAuth;
public class HomeActivity extends AppCompatActivity {
Button btnLogout;
Button customButton;
Switch switchEnableButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Button btn = findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
launchactivity();
}
});
btnLogout = findViewById(R.id.logout);
customButton = findViewById(R.id.custom_button);
switchEnableButton = findViewById(R.id.switch_enable_button);
customButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(HomeActivity.this, "Click", Toast.LENGTH_SHORT).show();
}
});
switchEnableButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
customButton.setEnabled(true);
} else {
customButton.setEnabled(false);
}
}
});
btnLogout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FirebaseAuth.getInstance().signOut();
Intent intToMain = new Intent(HomeActivity.this, LoginActivity.class);
startActivity(intToMain);
}
});
}
public void launchactivity(){
Intent intent = new Intent( HomeActivity.this, MapsActivity.class );
startActivity( intent );
}
}
I getting errors in homepage of my new app of helpline,I tried to check all but still not running please check and comment accordingly
Please review
Your code to define a fragment in xml is incorrectly. Pls read this: https://developer.android.com/training/basics/fragments/creating.
Hope this help.
You forgot about android:name="" attribute in your fragment. If you want to add your fragment dynamically, please use ViewGroup (FrameLayout, etc.)
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.
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