Java 应用程序在使用显式意图时崩溃
我是Java编程的初学者。我在安卓工作室工作,有明确的意图。我遇到了一个非常恼人的问题,每当我试图使用intent启动quick_活动时,我的应用程序就会崩溃。Java代码和XML似乎都很好。以下是XML和Java:Java 应用程序在使用显式意图时崩溃,java,android,android-intent,crash,Java,Android,Android Intent,Crash,我是Java编程的初学者。我在安卓工作室工作,有明确的意图。我遇到了一个非常恼人的问题,每当我试图使用intent启动quick_活动时,我的应用程序就会崩溃。Java代码和XML似乎都很好。以下是XML和Java: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@drawable/quiz_front"
android:layout_height="match_parent"
tools:context="com.example.shujah.games.Quiz_front">
<Button
android:id="@+id/start_quiz_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="78dp"
android:text=""
android:background="@android:color/transparent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/from_quiz_front_to_menu_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:textColor="@color/colorAccent"
android:layout_alignLeft="@+id/start_quiz_btn"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/start_quiz_btn"
android:text="BACK" />
</RelativeLayout>
以下是我想参加的活动:
public class Quiz_activity extends AppCompatActivity {
TextView choice1;
TextView choice2;
TextView choice3;
TextView choice4;
TextView num_right;
TextView num_left;
TextView sign;
TextView score;
Random r;
int scor;
Intent ii;
Button back_to_front;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz_activity);
back_to_front.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ii = new Intent(getApplicationContext(), Quiz_front.class);
startActivity(ii);
}
});
choice1 = (TextView) findViewById(R.id.choice1_tv);
choice2 = (TextView) findViewById(R.id.choice2_tv);
choice3 = (TextView) findViewById(R.id.choice3_tv);
choice4 = (TextView) findViewById(R.id.choice4_tv);
num_left = (TextView) findViewById(R.id.left_tv);
num_right = (TextView) findViewById(R.id.right_tv);
score = (TextView) findViewById(R.id.score_tv);
sign = (TextView) findViewById(R.id.sign_tv);
r = new Random();
/* choice1.setTextColor(Color.BLUE);
choice2.setTextColor(Color.BLUE);
choice3.setTextColor(Color.BLUE);
choice4.setTextColor(Color.BLUE);
num_right.setTextColor(Color.YELLOW);
num_left.setTextColor(Color.YELLOW);
sign.setTextColor(Color.YELLOW);*/
}
}
XML:
以下是Android Manifest.XML:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shujah.games">
<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">
<activity android:name=".MenuActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.shujah.games.RPSactivity" />
<activity android:name="com.example.shujah.games.Quiz_activity" />
<activity android:name="com.example.shujah.games.Quiz_front"></activity>
</application>
</manifest>
将back\u添加到\u front=按钮findviewbydr.id.back\u添加到\u question\u front
以前
back_to_front.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ii = new Intent(getApplicationContext(), Quiz_front.class);
startActivity(ii);
}
});
经常发布异常的StackTraceTachanx。这是我的一个相当业余的错误。无论如何,thnx
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shujah.games">
<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">
<activity android:name=".MenuActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.shujah.games.RPSactivity" />
<activity android:name="com.example.shujah.games.Quiz_activity" />
<activity android:name="com.example.shujah.games.Quiz_front"></activity>
</application>
</manifest>
back_to_front.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ii = new Intent(getApplicationContext(), Quiz_front.class);
startActivity(ii);
}
});