简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM