我有2个活动,我需要从GameActivity
开始MainActivity
,但是AndroidManifest
存在一些问题。我应该在那里写什么?
清单:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".GameActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.ALTERNATIVE" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnStart:
Intent intent = new Intent(this, GameActivity.class);
startActivityForResult(intent, 10);
break;
case R.id.btnExit:
finish();
break;
}
}
GameActivity
public class GameActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btnBack:
finish();
break;
}
}
}
xml activity_game
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".GameActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="@+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:onClick="onClick"
android:text="@string/btnBack" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="center"
android:text="0"
android:textSize="30dp" />
</LinearLayout>
<com.example.clicker.DrawView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Logcat消息:
2019-04-06 22:00:00.914 10196-10196/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 10196
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.GameActivity}: android.view.InflateException: Binary XML file line #33: Binary XML file line #33: Error inflating class com.example.clicker.DrawView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
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:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #33: Binary XML file line #33: Error inflating class com.example.clicker.DrawView
Caused by: android.view.InflateException: Binary XML file line #33: Error inflating class com.example.clicker.DrawView
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.clicker.DrawView" on path: DexPathList[[zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/base.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_resources_apk.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.myapplication.GameActivity.onCreate(GameActivity.java:12)
2019-04-06 22:00:00.922 10196-10196/com.example.myapplication E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
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:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
at android.app.LoadedApk.getResources(LoadedApk.java:1032)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
... 6 more
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.myapplication-UnaaN19LjC_yTurW970Ruw==/split_lib_slice_0_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
2019-04-06 22:00:00.923 10196-10196/com.example.myapplication E/AndroidRuntime: at android.app.LoadedApk.getResources(LoadedApk.java:1032)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
... 6 more
答案 0 :(得分:0)
您的清单没有问题。
GameActivity
已启动,但在尝试加载其布局时崩溃。
您尝试在View
中使用的自定义GameActivity
出现问题。
这是堆栈跟踪中的相关行:
Caused by: android.view.InflateException: Binary XML file line #33: Binary XML file line #33: Error inflating class com.example.clicker.DrawView
因此,问题是:DrawView.java
文件在哪里?
我怀疑,您要么没有复制它,要么需要在GameActivity
的版面xml文件中修复其包名。
请注意,错误提示为com.example.clicker.DrawView
,但您的应用程序包为com.example.myapplication
。