dimanche 20 octobre 2019

App keep stoping when testing in Android Studio

2019-10-20 19:17:13.479 5647-5683/com.example.listviewapp I/ple.listviewap: The ClassLoaderContext is a special shared library. 2019-10-20 19:17:13.559 5647-5647/com.example.listviewapp I/Perf: Connecting to perf service. 2019-10-20 19:17:13.565 5647-5647/com.example.listviewapp W/com.example.listviewapp: type=1400 audit(0.0:1191): avc: denied { read } for comm=45474C20496E6974 name="u:object_r:vendor_default_prop:s0" dev="tmpfs" ino=21652 scontext=u:r:untrusted_app:s0:c15,c257,c512,c768 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0 2019-10-20 19:17:13.578 5647-5722/com.example.listviewapp E/libc: Access denied finding property "vendor.debug.egl.profiler" 2019-10-20 19:17:13.565 5647-5647/com.example.listviewapp W/com.example.listviewapp: type=1400 audit(0.0:1192): avc: denied { read } for comm=45474C20496E6974 name="u:object_r:vendor_default_prop:s0" dev="tmpfs" ino=21652 scontext=u:r:untrusted_app:s0:c15,c257,c512,c768 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0 2019-10-20 19:17:13.578 5647-5722/com.example.listviewapp E/libc: Access denied finding property "vendor.debug.prerotation.disable" 2019-10-20 19:17:13.606 5647-5647/com.example.listviewapp D/AndroidRuntime: Shutting down VM

--------- beginning of crash

2019-10-20 19:17:13.608 5647-5647/com.example.listviewapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.listviewapp, PID: 5647 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.listviewapp/com.example.listviewapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2977) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3182) 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:1916) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6898) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference at androidx.appcompat.app.AppCompatDelegateImpl.(AppCompatDelegateImpl.java:249) at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182) at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520) at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:191) at com.example.listviewapp.MainActivity.(MainActivity.java:15) at java.lang.Class.newInstance(Native Method) at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69) at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:43) at android.app.Instrumentation.newActivity(Instrumentation.java:1232) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2965) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3182)  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:1916)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:193)  at android.app.ActivityThread.main(ActivityThread.java:6898)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)  2019-10-20 19:17:13.612 5647-5647/com.example.listviewapp W/OPDiagnose: getService:OPDiagnoseService NULL 2019-10-20 19:17:13.619 5647-5727/com.example.listviewapp D/OSTracker: OS Event: crash

this is the logcat when i test the app on my Physical device

I tried changing Gradle plugin from current version to previous but didn't help

Here is the MainActivity.java

package com.example.listviewapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    ListView MyList = (ListView)findViewById(R.id.MyList);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    final String[] foods = {"Bacon", "Tuna", "Potato", "Meatball", "Candy", "Ham", "Shushi",
            "Apple", "Orange", "Pizza", "Hotdog", "Chole Bhatoore", "Chole Kulche", "Pasta"};


    //Adapter as a converter
        ListAdapter LAObject = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, foods);
        MyList.setAdapter(LAObject);


        //item listener
        MyList.setOnItemClickListener(
                new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        String store = String.valueOf(parent.getItemAtPosition(position));
                        Toast.makeText(MainActivity.this, store, Toast.LENGTH_SHORT).show();
                    }
                }
        );
    }

}

I wonder why this happening on second attempt because the first time i ran it, it worked perfectly fine but when tried on second time it keeps stopping.

I think following files will also help you try to figure out the problem

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.example.listviewapp"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Aucun commentaire:

Enregistrer un commentaire