我的android项目有问题,我的项目很大,有很多方法,所以最近我尝试在我的xml文件中添加一个textview,它可以工作,但是当我尝试为textview添加id时,我的app崩溃了,所以我更改了textview的id,但是它仍然崩溃了,当我删除textview的id时,我的app工作了,
然后我读了日志:
11-16 21:26:33.269 13213 13213 E AndroidRuntime FATAL EXCEPTION: main
11-16 21:26:33.269 13213 13213 E AndroidRuntime Process: com.wanjy.dannie.rivchat, PID: 13213
11-16 21:26:33.269 13213 13213 E AndroidRuntime java.lang.RuntimeException: Unable to instantiate application android.support.multidex.MultiDexApplication: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/com.wanjy.dannie.rivchat-1/base.apk"],nativeLibraryDirectories=[/data/app/com.wanjy.dannie.rivchat-1/lib/x86, /system/lib, /vendor/lib, /data/downloads, /data/priv-downloads]]
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.LoadedApk.makeApplication(LoadedApk.java:802)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5392)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.ActivityThread.-wrap2(ActivityThread.java)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1548)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:102)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.os.Looper.loop(Looper.java:154)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:6138)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at java.lang.reflect.Method.invoke(Native Method)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
11-16 21:26:33.269 13213 13213 E AndroidRuntime Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/com.wanjy.dannie.rivchat-1/base.apk"],nativeLibraryDirectories=[/data/app/com.wanjy.dannie.rivchat-1/lib/x86, /system/lib, /vendor/lib, /data/downloads, /data/priv-downloads]]
11-16 21:26:33.269 13213 13213 E AndroidRuntime at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.Instrumentation.newApplication(Instrumentation.java:1022)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.LoadedApk.makeApplication(LoadedApk.java:796)
11-16 21:26:33.269 13213 13213 E AndroidRuntime ... 9 more
11-16 21:26:33.269 13213 13213 E AndroidRuntime Suppressed: java.io.IOException: Failed to open dex files from /data/app/com.wanjy.dannie.rivchat-1/base.apk because: Failure to verify dex file '/data/app/com.wanjy.dannie.rivchat-1/base.apk': out-of-order static field indexes 65535 and 0
11-16 21:26:33.269 13213 13213 E AndroidRuntime at dalvik.system.DexFile.openDexFileNative(Native Method)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at dalvik.system.DexFile.openDexFile(DexFile.java:367)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at dalvik.system.DexFile.<init>(DexFile.java:112)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at dalvik.system.DexFile.<init>(DexFile.java:77)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at dalvik.system.DexPathList.loadDexFile(DexPathList.java:359)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at dalvik.system.DexPathList.makeElements(DexPathList.java:323)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at dalvik.system.DexPathList.makeDexElements(DexPathList.java:263)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at dalvik.system.DexPathList.<init>(DexPathList.java:126)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:58)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:520)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.LoadedApk.getClassLoader(LoadedApk.java:553)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:1869)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.LoadedApk.getResources(LoadedApk.java:766)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.ContextImpl.<init>(ContextImpl.java:2057)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.ContextImpl.createAppContext(ContextImpl.java:2002)
11-16 21:26:33.269 13213 13213 E AndroidRuntime at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5298)
我在google上搜索了一下,找到了一些关于添加的答案
multiDexEnabled true;
https://ranjithexpertisers.medium.com/unable-to-instantiate-application-android-support-multidex-multidexapplication-2b09a31d10a
构建.gradle
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'bhrivchat'
keyPassword '123456a@'
storeFile file('../bhrivchat.jks')
storePassword '123456a@'
}
}
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
applicationId 'com.wanjy.dannie.rivchat'
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
//multiDexKeepFile file('multidex-config.txt')
}
debug {
signingConfig signingConfigs.config
}
}
productFlavors {
}
}
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'de.hdodenhof:circleimageview:2.2.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
compile 'com.google.firebase:firebase-core:9.8.0'
compile 'com.google.firebase:firebase-database:9.8.0'
compile 'com.google.firebase:firebase-storage:9.8.0'
compile 'com.google.firebase:firebase-auth:9.8.0'
testCompile 'junit:junit:4.12'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.yarolegovich:lovely-dialog:1.0.4'
compile 'com.android.support:cardview-v7:25.0.1'
compile 'com.android.support:percent:25.0.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
compile 'me.dm7.barcodescanner:zxing:1.9.8'
compile 'com.jakewharton:butterknife:8.8.1'
}
apply plugin: 'com.google.gms.google-services'
清单
<?xml version='1.0' encoding='utf-8'?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wanjy.dannie.rivchat">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name="com.wanjy.dannie.rivchat.ComputerScience"
android:theme="@style/AppTheme">
<activity
android:name="com.wanjy.dannie.rivchat.ui.LoginActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/MyThemeNoActionbar"/>
<activity
android:name="com.wanjy.dannie.rivchat.Home"
android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.wanjy.dannie.rivchat.ui.RegisterActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/MyThemeNoActionbar"/>
<activity
android:name="com.wanjy.dannie.rivchat.ui.AddGroupActivity"
android:theme="@style/MyThemeNoActionbar"/>
<activity
android:name="com.wanjy.dannie.rivchat.ui.AddPost"
/>
<activity
android:name="com.wanjy.dannie.rivchat.ui.AddBook"
/>
<activity
android:name="com.wanjy.dannie.rivchat.ui.addVideo"
android:theme="@style/MyThemeNoActionbar"/>
<activity
android:name="com.wanjy.dannie.rivchat.ui.AddSound"
/>
<activity
android:name="com.wanjy.dannie.rivchat.ui.CommentActivity"
/>
<activity
android:name="com.wanjy.dannie.rivchat.ui.ImageViewerActivity"
android:theme="@style/Translucent"/>
<activity
android:name="com.wanjy.dannie.rivchat.ui.DecoderActivity"
android:theme="@style/MyThemeNoActionbar"/>
<receiver android:name="com.wanjy.dannie.rivchat.MyReciever">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
<action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
</intent-filter>
</receiver>
<service
android:name="com.wanjy.dannie.rivchat.service.ServiceNotif"
android:enabled="true"
android:exported="true"/>
<service
android:name="com.wanjy.dannie.rivchat.service.FriendChatService"
android:exported="false"
android:persistent="true"/>
</application>
</manifest>
我的应用程序类
package com.wanjy.dannie.rivchat;
import android.app.Application;
import android.content.res.Configuration;
//import android.support.multidex.MultiDexApplication;
public class ComputerScience extends Application {
// Called when the application is starting, before any other application objects have been created.
// Overriding this method is totally optional!
@Override
public void onCreate() {
super.onCreate();
// Required initialization logic here!
}
// Called by the system when the device configuration changes while your component is running.
// Overriding this method is totally optional!
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
// This is called when the overall system is running low on memory,
// and would like actively running processes to tighten their belts.
// Overriding this method is totally optional!
@Override
public void onLowMemory() {
super.onLowMemory();
}
}
所以我尝试了这个解决方案,但我的应用程序仍然崩溃,那么问题是什么呢,我该怎么解决这个问题?
1条答案
按热度按时间q9rjltbz1#
如果在代码中实现了应用程序类(如果没有,则创建它)。使用多索引应用程序扩展它。
并在manifest application标记中添加应用程序类的名称-