我的代码正在更新前运行,我更新了我的grandle和支持库等,并且它停止了工作。 试图修复它只会引起循环反应。
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
public class DashboardLightActivity extends AppCompatActivity {
private TabLayout tabLayout;
private ViewPager viewPager;
private ViewPageAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboardlight);
tabLayout = findViewById(R.id.tab_layout);
viewPager = findViewById(R.id.pager);
adapter = new ViewPageAdapter(getSupportFragmentManager());
adapter.AddFragment(new FragmentRed(), "Red");
adapter.AddFragment(new FragmentYellow(), "Yellow");
adapter.AddFragment(new FragmentGreen(), "Green");
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
tabLayout.getTabAt(0).setIcon(R.drawable.settings_icon);
tabLayout.getTabAt(1).setIcon(R.drawable.seatbelt_symbol);
tabLayout.getTabAt(2).setIcon(R.drawable.srs);
}
}
<LinearLayout
android:id="@+id/main_layout"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v4.view.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorGray"
android:minHeight="?attr/actionBarSize" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
我的依赖项列表。可能是错误的实现,但应该可行
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-database:18.0.0'
implementation 'com.google.firebase:firebase-storage:18.0.0'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'org.jetbrains:annotations-java5:15.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
}
大项目:错误版本?
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms:google-services:4.2.0'
运行该应用程序时出现错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mac.ben.carlendar, PID: 7688
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mac.ben.carlendar/com.mac.ben.carlendar.DashboardLightActivity}: android.view.InflateException: Binary XML file line #10 in com.mac.ben.carlendar:layout/activity_dashboardlight: Binary XML file line #10 in com.mac.ben.carlendar:layout/activity_dashboardlight: Error inflating class android.support.v4.view.TabLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3260)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3396)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2009)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7319)
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:934)
Caused by: android.view.InflateException: Binary XML file line #10 in com.mac.ben.carlendar:layout/activity_dashboardlight: Binary XML file line #10 in com.mac.ben.carlendar:layout/activity_dashboardlight: Error inflating class android.support.v4.view.TabLayout
Caused by: android.view.InflateException: Binary XML file line #10 in com.mac.ben.carlendar:layout/activity_dashboardlight: Error inflating class android.support.v4.view.TabLayout
Caused by: java.lang.ClassNotFoundException: android.support.v4.view.TabLayout
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at android.view.LayoutInflater.createView(LayoutInflater.java:815)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.mac.ben.carlendar.DashboardLightActivity.onCreate(DashboardLightActivity.java:20)
at android.app.Activity.performCreate(Activity.java:7783)
at android.app.Activity.performCreate(Activity.java:7772)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3235)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3396)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2009)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7319)
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:934)
E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.view.TabLayout" on path: DexPathList[[zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/base.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_dependencies_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_resources_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_0_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_1_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_2_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_3_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_4_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_5_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_6_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_7_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_8_apk.apk", zip file "/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/lib/x86, /system/lib, /system/product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 28 more
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:365)
at dalvik.system.DexFile.<init>(DexFile.java:107)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:444)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:403)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:126)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:101)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:851)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:950)
at android.app.LoadedApk.getResources(LoadedApk.java:1188)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2462)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2454)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6306)
at android.app.ActivityThread.access$1300(ActivityThread.java:220)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1852)
... 6 more
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.mac.ben.carlendar-PeGPUttOAmlYqdU8pGOO0Q==/split_lib_slice_1_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:365)
at dalvik.system.DexFile.<init>(DexFile.java:107)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:444)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:403)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
E/AndroidRuntime: at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:126)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:101)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:851)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:950)
at android.app.LoadedApk.getResources(LoadedApk.java:1188)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2462)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2454)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6306)
at android.app.ActivityThread.access$1300(ActivityThread.java:220)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1852)
... 6 more
如何使相同的代码像以前一样工作,或者需要进行哪些更改才能使其再次工作。代码未更改。