0

每当我尝试在应用程序中打开一项活动(名称为quizActivity)时,应用程序就会崩溃并出现以下错误:

Unknown bits set in runtime_flags: 0x28000
2020-08-17 21:41:20.561 12713-12713/inspire2connect.inspire2connect E/LoadedApk: Unable to instantiate appComponentFactory
    java.lang.ClassNotFoundException: Didn't find class "inspire2connect.inspire2connect.whateverString" on path: DexPathList[[zip file "/data/app/inspire2connect.inspire2connect-tnn4gqGg6Qg8JLYvyTp51A==/base.apk"],nativeLibraryDirectories=[/data/app/inspire2connect.inspire2connect-tnn4gqGg6Qg8JLYvyTp51A==/lib/arm64, /system/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.LoadedApk.createAppFactory(LoadedApk.java:272)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:881)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:976)
        at android.app.LoadedApk.getResources(LoadedApk.java:1227)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2562)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2554)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6698)
        at android.app.ActivityThread.access$1700(ActivityThread.java:240)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2068)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:238)
        at android.app.ActivityThread.main(ActivityThread.java:7798)
        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:995)
2020-08-17 21:41:20.880 12713-12777/inspire2connect.inspire2connect E/Perf: Fail to get file list inspire2connect.inspire2connect
2020-08-17 21:41:20.880 12713-12777/inspire2connect.inspire2connect E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array

这是整个项目的链接: github.com/StealthViper/WashKaro

我一直在尝试查看错误是什么,但似乎无法纠正。大多数答案都表明清单文件有问题,但是当我在清单文件中进行这些更改时不起作用。这是清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="inspire2connect.inspire2connect">
    
    <uses-feature android:name="android.hardware.location.gps" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:appComponentFactory="whateverString"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"
        android:theme="@style/AppTheme"
        tools:replace="android:appComponentFactory">
        <activity android:name=".satyaChat.ChatActivity"></activity>
        <activity android:name=".home.homeActivity" /> <!-- <activity android:name=".male_female_2" /> -->
        <activity android:name=".home.WelcomeActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".survey.maleFemaleActivity" />
        <activity android:name=".news.text2speech2_2Activity" />
        <activity android:name=".about.aboutActivity" />
        <activity android:name=".news.onAIrActivity" /> 

        <activity android:name=".mythGuidelineUpdates.UpdateActivity" />
        <activity android:name=".tweets.tweetActivity" />
        <activity android:name="inspire2connect.inspire2connect.quiz.quizActivity" />
        <activity android:name="inspire2connect.inspire2connect.quiz.scoreActivity" />
        <activity android:name=".utils.urlActivity" />

        <service
            android:name=".utils.MyFirebaseMessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <activity android:name=".mythGuidelineUpdates.guidelineViewActivity" />
        <activity android:name=".home.InfographicsActivity" />

        <meta-data
            android:name="firebase_messaging_auto_init_enabled"
            android:value="false" />
        <meta-data
            android:name="firebase_analytics_collection_enabled"
            android:value="true" />
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/colorAccent" />

    </application>

</manifest>

我还附上了我的 build.gradle 文件,因为错误可能来自那里,如一些答案所示:

  apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.gms.google-services'
android {
    compileSdkVersion 29

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "inspire2connect.inspire2connect"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 24
        versionName "4.1"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    def room_version = "2.2.5"
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // Android & UI
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//    implementation 'org.jetbrains:annotations-java5:15.0'

    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'com.google.android.play:core:1.7.3'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.mediarouter:mediarouter:1.1.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation "androidx.viewpager:viewpager:1.0.0"
    implementation 'android.arch.work:work-runtime:1.0.1'
    implementation 'androidx.preference:preference:1.1.1'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.legacy:legacy-support-v13:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
    implementation 'com.google.guava:guava:27.0.1-android'
    implementation 'com.android.volley:volley:1.1.1'

    // Firebase
    implementation 'com.google.firebase:firebase-database:19.3.0'
    implementation 'com.firebaseui:firebase-ui-auth:6.2.0'
    implementation 'com.google.firebase:firebase-auth:19.3.1'
    implementation 'com.google.firebase:firebase-storage:19.1.1'
    implementation 'com.google.firebase:firebase-inappmessaging-display:19.0.7'
    implementation 'com.google.firebase:firebase-analytics:17.4.3'
    implementation 'com.google.firebase:firebase-messaging:20.2.0'
    implementation 'com.google.firebase:firebase-core:17.4.3'
    implementation 'com.google.firebase:firebase-iid:20.2.0'
    implementation 'com.google.firebase:firebase-crashlytics:17.0.1'

    // Room
    implementation "androidx.room:room-runtime:$room_version"
    annotationProcessor "androidx.room:room-compiler:$room_version"
    testImplementation "androidx.room:room-testing:$room_version"

    // Third Party
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'
    implementation 'com.llollox:androidtoggleswitch:2.0.1'
    implementation 'com.sefford:circular-progress-drawable:1.31@aar'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
    implementation 'com.jakewharton:butterknife:10.2.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
    implementation 'in.srain.cube:grid-view-with-header-footer:1.0.12'

}

这是 quizActivity 类的代码:

public class quizActivity extends BaseActivity implements View.OnClickListener{
    private static final int MY_REQUEST_CODE = 2399;
    TextView question, option1_text, option2_text, option3_text, option4_text,qCount,timer;
    ConstraintLayout[] options = new ConstraintLayout[4];
    public static final String TAG = "QuizActivity";
    public static final String seen_questions_tag = "QuestionsShown";
    public ArrayList<questionObject> result;
    public ArrayList<questionObject> selected_questions;
    public ArrayList<questionObject> seen_questions;
    DatabaseReference databaseReference;
    private Dialog loadingDialog;
    private CountDownTimer countDown;
    private int quesNum;
    private int score;
    private boolean setDate;


    public void update_handle() {
        final AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(this);
        Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
        appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener<AppUpdateInfo> () {
            @Override
            public void onSuccess(AppUpdateInfo appUpdateInfo) {
                if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
                    try {
                        appUpdateManager.startUpdateFlowForResult(
                                appUpdateInfo, AppUpdateType.IMMEDIATE, quizActivity.this, MY_REQUEST_CODE);
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                    }

                } else if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
                    try {
                        appUpdateManager.startUpdateFlowForResult(
                                appUpdateInfo, AppUpdateType.FLEXIBLE, quizActivity.this, MY_REQUEST_CODE);
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == MY_REQUEST_CODE) {
            if (resultCode != RESULT_OK) {
                Loge("UPDATE_STATUS", "Update flow failed! Result code: " + resultCode);
            }
        }
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext( LocaleHelper.onAttach(newBase));
    }


    private void setUpdates() {
        quizReference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                result = new ArrayList<>();
                for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                    questionObject obj = new questionObject (snapshot.child("question_"+ getCurLang()).getValue().toString(),snapshot.child("option1_"+ getCurLang ()).getValue().toString(),snapshot.child("option2_"+ getCurLang ()).getValue().toString(),snapshot.child("option3_"+ getCurLang ()).getValue().toString(),snapshot.child("option4_"+ getCurLang ()).getValue().toString(),Integer.valueOf ( snapshot.child ( "answer" ).getValue ().toString () ),snapshot.child("explanation_"+ getCurLang ()).getValue().toString(),snapshot.child("correct_attempts").getValue().toString (),snapshot.child("total_attempts").getValue().toString(), snapshot.getKey (),snapshot.child ( "key" ).getValue(Integer.class)  );

                    result.add(new questionObject (obj.question,
                            obj.option1,obj.option2,obj.option3,obj.option4, obj.answer,obj.explanation,obj.correct_attempts,obj.total_attempts, obj.id,obj.key));
                }

                selectQuestionSet(result);

                loadingDialog.dismiss();
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });
    }

    private void setQuestion(){
        timer.setText ( String.valueOf ( 30 ) );

        question.setText ( selected_questions.get(0).getQuestion () );
        option1_text.setText ( selected_questions.get(0).getOption1 () );
        option2_text.setText ( selected_questions.get(0).getOption2 () );
        option3_text.setText ( selected_questions.get(0).getOption3 () );
        option4_text.setText ( selected_questions.get(0).getOption4 () );

        qCount.setText(String.valueOf(1) + "/" + String.valueOf(selected_questions.size()));

        startTimer();

        quesNum = 0 ;
    }

    private void startTimer()
    {
        countDown = new CountDownTimer (32000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                if(millisUntilFinished < 30000)
                    timer.setText(String.valueOf(millisUntilFinished / 1000));
            }

            @Override
            public void onFinish() {
                changeQuestion();
            }
        };

        countDown.start();

    }



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

        question = findViewById ( R.id.question_text );
        qCount = findViewById ( R.id.quest_num );
        timer = findViewById(R.id.countdown);

        option1_text = findViewById ( R.id.option_1_text );
        option2_text = findViewById ( R.id.option_2_text );
        option3_text = findViewById ( R.id.option_3_text );
        option4_text = findViewById ( R.id.option_4_text );

        options[0] = findViewById ( R.id.option_1_tile );
        options[0].setOnClickListener ( this );
        options[1] = findViewById ( R.id.option_2_tile );
        options[1].setOnClickListener ( this );
        options[2] = findViewById ( R.id.option_3_tile );
        options[2].setOnClickListener ( this );
        options[3] = findViewById ( R.id.option_4_tile );
        options[3].setOnClickListener ( this );

        loadingDialog = new Dialog(quizActivity.this);
        loadingDialog.setContentView(R.layout.loading_progressbar);
        loadingDialog.setCancelable(false);
        loadingDialog.getWindow().setBackgroundDrawableResource(R.drawable.progress_background);
        loadingDialog.getWindow().setLayout( ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        loadingDialog.show();

        setDate = false;

        getSupportActionBar().setBackgroundDrawable(new ColorDrawable( Color.TRANSPARENT));

        Intent i = getIntent();

        String type = i.getStringExtra(TYPE);
        String date = i.getStringExtra(DATE);

        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext ());
        SharedPreferences.Editor editor = sharedPrefs.edit();
        Gson gson = new Gson();
        String json = gson.toJson(seen_questions);
        editor.putString(seen_questions_tag, json);
        editor.commit();

        switch (date) {
            case DATE_YES:
                setDate = true;
                break;
            default:
                setDate = false;
                break;
        }

        switch (type) {
            case UPDATES:
                databaseReference = governmentReference;
                getSupportActionBar().setTitle(R.string.govt_updates_act);
                break;
            case GUIDELINES:
                databaseReference = guidelinesReference;
                getSupportActionBar().setTitle(R.string.guidelines_act);
                break;
            case MYTH:
                databaseReference = mythReference;
                getSupportActionBar().setTitle(R.string.myth_act);
                break;
            case FAQ:
                databaseReference = faqsReference;
                getSupportActionBar().setTitle(R.string.faqs_tile);
                break;
            case SUCCESS_STORIES:
                databaseReference = successStoriesReference;
                getSupportActionBar().setTitle(R.string.success_stories_tile);
                break;
            case TWEETS:
                databaseReference = tweetsReference;
                getSupportActionBar().setTitle( R.string.social_media_title);
                break;
            case QUIZ:
                databaseReference = quizReference;
                getSupportActionBar ().setTitle (getString( R.string.quiz_title));
                getSupportActionBar().setBackgroundDrawable(new ColorDrawable ( Color.TRANSPARENT));
                break;
            default:
                Logv(TAG, "Invalid Intent");
                break;
        }

//        result = new ArrayList<>();
//        result.add(new questionObject ("No Question Available", "No Option Available","No Option Available","No Option Available","No Option Available",0,"No Data Available","No Data Available","No Data Available", "No Data Available",0));

        setUpdates();

        score = 0;

    }

    @Override
    public void onClick(View view) {

        int selectedOption = 0 ;

        switch (view.getId()){

            case R.id.option_1_tile :
                selectedOption = 1;
                break;
            case R.id.option_2_tile :
                selectedOption = 2;
                break;
            case R.id.option_3_tile :
                selectedOption = 3;
                break;
            case R.id.option_4_tile :
                selectedOption = 4;
                break;

            default:

        }
            countDown.cancel ();
            checkAnswer(selectedOption, view);
    }

    private void checkAnswer(int selectedOption, View view)
    {

        if(selectedOption == selected_questions.get(quesNum).getAnswer())
        {
            //Right Answer
            (view).setBackgroundTintList(ColorStateList.valueOf(Color.GREEN));
            quizReference.child ( selected_questions.get ( quesNum ).getId () ).child("correct_attempts").setValue( String.valueOf (Integer.valueOf (selected_questions.get ( quesNum ).getCorrect_attempts ())+1 ));
            quizReference.child ( selected_questions.get ( quesNum ).getId () ).child("total_attempts").setValue( String.valueOf (Integer.valueOf (selected_questions.get ( quesNum ).getTotal_attempts ())+1 ));
            score++;

        }
        else
        {
            //Wrong Answer
            (view).setBackgroundTintList(ColorStateList.valueOf( Color.RED));

            quizReference.child ( selected_questions.get ( quesNum ).getId() ).child("total_attempts").setValue( String.valueOf (Integer.valueOf (selected_questions.get ( quesNum ).getTotal_attempts ())+1 ));

            switch (selected_questions.get(quesNum).getAnswer ())
            {
                case 1:
                    options[0].setBackgroundTintList( ColorStateList.valueOf(Color.GREEN));
                    break;
                case 2:
                    options[1].setBackgroundTintList(ColorStateList.valueOf(Color.GREEN));
                    break;
                case 3:
                    options[2].setBackgroundTintList(ColorStateList.valueOf(Color.GREEN));
                    break;
                case 4:
                    options[3].setBackgroundTintList(ColorStateList.valueOf(Color.GREEN));
                    break;

            }

        }

        Handler handler = new Handler();
        handler.postDelayed( () -> changeQuestion(), 2000);



    }

    private void changeQuestion()
    {
        if( quesNum < selected_questions.size() - 1)
        {
            quesNum++;

            playAnim(question,0,0);
            playAnim(option1_text,0,1);
            playAnim(option2_text,0,2);
            playAnim(option3_text,0,3);
            playAnim(option4_text,0,4);

            qCount.setText(String.valueOf(quesNum+1) + "/" + String.valueOf(selected_questions.size()));

            timer.setText(String.valueOf(30));
            startTimer();

        }
        else
        {
            // Go to Score Activity
            Intent intent = new Intent(quizActivity.this,scoreActivity.class);
            intent.putExtra("SCORE", String.valueOf(score) + "/" + String.valueOf(selected_questions.size()));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);

        }


    }

    private void playAnim(final View view, final int value, final int viewNum)
    {

        view.animate().alpha(value).scaleX(value).scaleY(value).setDuration(500)
                .setStartDelay(100).setInterpolator(new DecelerateInterpolator ())
                .setListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if(value == 0)
                        {
                            switch (viewNum)
                            {
                                case 0:
                                    ((TextView)view).setText(selected_questions.get(quesNum).getQuestion());
                                    break;
                                case 1:
                                    ((TextView)view).setText(selected_questions.get(quesNum).getOption1 ());
                                    break;
                                case 2:
                                    ((TextView)view).setText(selected_questions.get(quesNum).getOption2 ());
                                    break;
                                case 3:
                                    ((TextView)view).setText(selected_questions.get(quesNum).getOption3 ());
                                    break;
                                case 4:
                                    ((TextView)view).setText(selected_questions.get(quesNum).getOption4 ());
                                    break;

                            }


                            if(viewNum != 0)
                                (view).setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#E99C03")));


                            playAnim(view,1,viewNum);

                        }

                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });

    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();

        countDown.cancel();
    }




    public void selectQuestionSet(ArrayList<questionObject> result){

        try {
            selected_questions.clear();
        } catch (Exception e) {
            e.printStackTrace ();
        }

        Collections.sort(result);
        for (questionObject object: result) {
            if(selected_questions.size () < 5 && checkUsage(object.key) && checkLimit()){
                //display the question
                //append key to stored list
                selected_questions.add (object);
                seen_questions.add(object);
                SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext ());
                SharedPreferences.Editor editor = sharedPrefs.edit();
                Gson gson = new Gson();
                String json = gson.toJson(seen_questions);
                editor.putString(seen_questions_tag, json);
                editor.commit();

            }
            else if(selected_questions.size() < 5 && !checkLimit()) {
                seen_questions.clear();
                selectQuestionSet(result);
            }

            if(selected_questions.size () == 5){
                break;
            }


        }

        setQuestion ();
    }

    public boolean checkUsage(int key){
        //Check whether key already used or not here
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext ());
        Gson gson = new Gson();
        String json = sharedPrefs.getString(seen_questions_tag, "");
        Type type = new TypeToken<List<questionObject>> () {}.getType();
        List<questionObject> arrayList = gson.fromJson(json, type);
        for (questionObject object : arrayList){
            if (object.key == key){
                return false;
            }
        }
        return true;
    }

    public boolean checkLimit(){
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext ());
        Gson gson = new Gson();
        String json = sharedPrefs.getString(seen_questions_tag, "");
        Type type = new TypeToken<List<questionObject>> () {}.getType();
        List<questionObject> arrayList = gson.fromJson(json, type);
        if(arrayList.size() > 95){
            return false;
        }
        return true;
    }

}
4

1 回答 1

0

工具:replace="android:appComponentFactory"

从清单文件中删除它并转到文件并单击无效缓存/重新启动

于 2020-08-19T19:54:54.510 回答