我被这个问题困扰了,我得快速解决这个问题。请帮帮我。所以目前我每次粘贴一些我在网上找到的新代码时都会遇到崩溃。 [附注: IM在android系统编程对于新手]我的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>
检查红色日志和张贴在这里。 – TruongHieu
将您的活动添加到您的清单..由于意图活动导致其崩溃尚未注册 – ZeroOne