我正在上一个需要在Android Studio中构建应用程序的课程。教授没有帮助,我无法让应用程序工作。我之前从未使用过Android Studio,而且我完全依靠Google搜索来完成整个项目。如果有帮助,我正在使用模拟器来显示我的应用程序。
有人可以帮助我吗?
这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ashly.recipeapp">
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:fullBackupContent="true"
android:allowBackup="true">
<activity
android:name=".SplashScreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="com.example.ashly.recipeapp.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http//"
android:host="recipe-app.com"
android:pathPrefix="/recipes"/>
</intent-filter>
</activity>
</application>
这是我的主要活动:
package com.example.ashly.recipeapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent openMainActivity = new Intent ("com.example.ashly.recipeapp.MainActivity");
startActivity(openMainActivity);
}
}
这是我的启动画面:
package com.example.ashly.recipeapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.splashTheme);
super.onCreate(savedInstanceState);
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
startActivity(intent);
finish();
}
}
我得到的错误:
01-12 12:17:34.255 1824-1824/com.example.ashly.recipeapp E/AndroidRuntime:
FATAL EXCEPTION: main
Process: com.example.ashly.recipeapp, PID: 1824
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ashly.recipeapp/com.example.ashly.recipeapp.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.ashly.recipeapp.MainActivity }
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.ashly.recipeapp.MainActivity }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3424)
at android.app.Activity.startActivityForResult(Activity.java:3385)
at android.app.Activity.startActivity(Activity.java:3627)
at android.app.Activity.startActivity(Activity.java:3595)
at com.example.ashly.recipeapp.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
为什么要在onCreate Mainactivity方法中启动Mainactivity? 只需从Mainactivity onCreate方法中删除以下两行:
Intent openMainActivity = new Intent ("com.example.ashly.recipeapp.MainActivity");
startActivity(openMainActivity);
答案 1 :(得分:0)
从MainActivity中删除此代码并开始工作
Intent openMainActivity = new Intent ("com.example.ashly.recipeapp.MainActivity");
startActivity(openMainActivity);