有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java应用程序重新启动,由于AndroidRuntime异常而无法运行

Gradle构建成功logcat显示E/AndroidRuntime:致命异常:main

-----Logcat错误------------

07-27 23:04:54.813 21702-21702/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.inoalexander.justjava, PID: 21702
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.inoalexander.justjava/com.example.inoalexander.justjava.mainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.inoalexander.justjava.mainActivity" on path: DexPathList[[zip file "/data/app/com.example.inoalexander.justjava-2/base.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.inoalexander.justjava-2/lib/arm64, /system/lib64, /vendor/lib64]]
    at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2819)
    at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
    at 安卓.app.ActivityThread.-wrap14(ActivityThread.java)
    at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
    at 安卓.os.Handler.dispatchMessage(Handler.java:102)
    at 安卓.os.Looper.loop(Looper.java:154)
    at 安卓.app.ActivityThread.main(ActivityThread.java:6682)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1534)
    at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:1424)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.inoalexander.justjava.mainActivity" on path: DexPathList[[zip file "/data/app/com.example.inoalexander.justjava-2/base.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.inoalexander.justjava-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.inoalexander.justjava-2/lib/arm64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at 安卓.app.Instrumentation.newActivity(Instrumentation.java:1086)
    at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2809)
    at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
    at 安卓.app.ActivityThread.-wrap14(ActivityThread.java) 
    at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
    at 安卓.os.Handler.dispatchMessage(Handler.java:102) 
    at 安卓.os.Looper.loop(Looper.java:154) 
    at 安卓.app.ActivityThread.main(ActivityThread.java:6682) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1534) 
    at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:1424) 

-----Java代码从这里开始-----------

package com.example.inoalexander.justjava;

import 安卓.os.Bundle;
import 安卓.support.v7.app.AppCompatActivity;
import 安卓.view.View;
import 安卓.widget.TextView;

/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {

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

/**
 * This method is called when the order button is clicked.
 */
public void submitOrder(View view) {
    display(1);
}

/**
 * This method displays the given quantity value on the screen.
 */
private void display(int number) {
    TextView quantityTextView = (TextView)            findViewById(R.id.quantity_text_view);
    quantityTextView.setText("" + number);
}

}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:orientation="vertical"
tools:context=".MainActivity">

-----------XML代码从这里开始----------------

<TextView

    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:textColor="#000000"
    安卓:textSize="16sp"
    安卓:layout_marginBottom="16dp"
    安卓:layout_marginLeft="16dp"
    安卓:text="Quantity" />
<TextView
    安卓:id="@+id/quantity_text_view"
    安卓:layout_width="wrap_content"
    安卓:layout_height="wrap_content"
    安卓:textColor="#000000"
    安卓:textSize="16sp"
    安卓:layout_marginLeft="16dp"
    安卓:layout_marginBottom="16dp"
    安卓:text="0" />
<Button
    安卓:id="@+id/button_id"
    安卓:layout_height="wrap_content"
    安卓:layout_width="wrap_content"
    安卓:layout_marginLeft="16dp"
    安卓:text="Order"
    安卓:onClick="submitOrder"/>




</LinearLayout>

我不确定,因为这是我开发的第一个不是卡片的应用程序之一。我不知道为什么它没有在我的手机上运行。我正在使用Galaxy Note 5来运行我的构建

构建Gradle成功,没有给我任何错误,但当我尝试在我的设备上运行它时,它会不断尝试重新启动应用程序,直到它最终导致应用程序崩溃。我在这里看到了一些答案,并被指示查看我在安卓 studio中的Logcat

我真的不知道我们是从Logcat开始的,或者它告诉我什么,我已经看到这个错误有很多变化,但没有一个特定于我的Logcat中的每个错误


共 (2) 个答案

  1. # 1 楼答案

    异常表示它试图查找类mainActivity,但在代码中有MainActivity

    确保AndroidManifest.xml中的活动类名与代码匹配

  2. # 2 楼答案

    multidextrue设置为应用程序级build.gradle文件,如下所示

    android {
        compileSdkVersion 27
        useLibrary 'org.apache.http.legacy'
        defaultConfig {
            applicationId "com.core.######"
            minSdkVersion 16
            targetSdkVersion 27
            versionCode 1
            versionName "1.0"
            multiDexEnabled true // here change
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    
        }
    }
    

    还要添加依赖项

    implementation 'com.android.support:multidex:1.0.3'
    

    最后,别忘了清理和重建项目