【发布时间】:2019-01-13 19:21:57
【问题描述】:
我正在尝试学习 Android 开发并已完成基本教程。我正在制作高尔夫记分卡应用程序。最初我从主屏幕 -> SelectCourseActivity -> 记分卡。一切正常,但我想摆脱 SelectCourseActivity,所以我试图让主屏幕上的主按钮直接进入记分卡,但现在它总是抛出这个异常:
catch (InvocationTargetException e) {
throw new IllegalStateException(
"Could not execute method for android:onClick", e);
}
这里是按钮 OnClick 的代码:
public void Scorecard(View view) {
Intent MyIntent = new Intent(this, ScorecardActivity.class);
startActivity(MyIntent);
}
是的,我已经进入 AndroidManifest 并将 ScorecardActivity 的父级设置为 Homescreen。
<application
android:allowBackup="true"
android:icon="@mipmap/wgcc_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/wgcc_icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".HomeScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SelectCourseActivity"
android:parentActivityName=".HomeScreen" />
<activity
android:name=".ScorecardActivity"
android:parentActivityName=".HomeScreen" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown"/>
</application>
即使在我使用 Git 使一切恢复正常后,ScorecardActivity 仍然无法启动。我感谢任何和所有的帮助!如果需要更多信息,请告诉我。
【问题讨论】:
-
我不确定这是否能解决问题,但请尝试在此行中添加
Homescreen.this而不是仅添加thisIntent MyIntent = new Intent(this, ScorecardActivity.class); -
为什么你的清单中有一个微调器?
标签: java android android-studio button android-activity