我已经被这个问题搞砸了,我得快速解决这个问题。请帮我。因此,每当我粘贴一些我在网上找到的新代码时,我每次都会遇到崩溃。 [附注:我是android编程的新手]
这是我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="birada1.tulungatung.ph.myapplication2">
<application
android:allowBackup="true"
android:icon="@mipmap/chess_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我对MainActivity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity implements View.OnClickListener {
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button one = (Button) findViewById(R.id.button2);
Button two = (Button) findViewById(R.id.button3);
Button three = (Button) findViewById(R.id.button4);
one.setOnClickListener(this);
two.setOnClickListener(this);
three.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button2:
Intent intenthistory = new Intent(this, ChessHistoryActivity.class);
startActivity(intenthistory);
// do your code
break;
case R.id.button3:
Intent intenthistory2 = new Intent(this, LearnChessActivity.class);
startActivity(intenthistory2);
break;
case R.id.button4:
Intent intenthistory3 = new Intent(this, GrandmastersActivity.class);
startActivity(intenthistory3);
break;
default:
}
}
}
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/img_view3"
android:layout_width="wrap_content"
android:layout_height="95dp"
android:contentDescription="@string/hellow"
app:srcCompat="@drawable/boom" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:onClick="btnClick1"
android:text="@string/c_history" />
<ImageView
android:id="@+id/img_view4"
android:layout_width="wrap_content"
android:layout_height="101dp"
android:contentDescription="@string/hellow"
app:srcCompat="@drawable/chess_moves_three" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="btnClick2"
android:background="@color/colorPrimaryDark"
android:text="@string/c_moves" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="113dp"
android:contentDescription="@string/hellow"
app:srcCompat="@drawable/grandmasters" />
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:onClick="btnClick3"
android:text="@string/c_grandmasters" />
</LinearLayout>
答案 0 :(得分:1)
从清单中删除您的应用程序代码并粘贴此应用程序代码并尝试将解决您的问题。
<application
android:allowBackup="true"
android:icon="@mipmap/chess_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ChessHistoryActivity"/>
<activity android:name=".LearnChessActivity"/>
<activity android:name=".GrandmastersActivity"/>
</application>
答案 1 :(得分:0)
您是否在AndroidManifest.xml中声明了ChessHistoryActivity / LearnChessActivity / GrandmastersActivity? 如果没有添加
<activity android:name=".ChessHistoryActivity"
android:launchMode="singleTask" />
<activity android:name=".LearnChessActivity"
android:launchMode="singleTask" />
<activity android:name=".GrandmastersActivity"
android:launchMode="singleTask" />
答案 2 :(得分:0)
首先将ChessHistoryActivity.java
,LearnChessActivity.java
和GrandmastersActivity.java
类添加到您的java source
文件夹(If not added yet)
。
文件夹: ./app/src/main/java/birada1.tulungatung.ph.myapplication2/
在ChessHistoryActivity
文件中声明LearnChessActivity
,GrandmastersActivity
和AndroidManifest.xml
。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="birada1.tulungatung.ph.myapplication2">
<application
android:allowBackup="true"
android:icon="@mipmap/chess_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ChessHistoryActivity" />
<activity android:name=".LearnChessActivity" />
<activity android:name=".GrandmastersActivity" />
</application>
</manifest>
希望这会有所帮助〜