我认为我的活动存在问题,因为它可以正常运行初始屏幕,但是当它进入主页时会出现强制关闭错误。如果您能看到我的home.java
代码是否正确,我也很感激我基本上想打开其他活动并使用退出按钮退出应用程序。
安卓清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.decrypter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
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=".Home"
android:label="@string/title_activity_home" >
<intent-filter>
<action android:name="com.example.decrypter.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
主页.java
package com.example.decrypter;
import android.os.Bundle;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.AdapterView.OnItemSelectedListener;
public class Home extends Activity implements OnItemSelectedListener {
Button btn_start,btn_about,btn_exit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
btn_start = (Button) findViewById(R.id.btn_start);
btn_about = (Button) findViewById(R.id.btn_about);
btn_exit = (Button) findViewById(R.id.btn_exit);
btn_start.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
Intent start = new Intent(Home.this, MainPage.class);
Home.this.startActivity(start);
}
});
btn_about.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
Intent about = new Intent(Home.this, about.class);
Home.this.startActivity(about);
}
});
btn_exit.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
System.exit(0);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.home, menu);
return true;
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
字符串.xml
<string name="app_name">decrypter</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main_page">MainPage</string>
<string name="title_activity_home">Home</string>
<string name="prompt">- </string>
<string-array name="numbers">
<item >1</item>
<item >2</item>
<item>3</item>
<item >4</item>
<item>5</item>
<item >6</item>
<item >7</item>
<item >8</item>
<item>9</item>
</string-array>
主页.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/btn_about"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/home" >
<Button
android:id="@+id/btn_start"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="183dp"
android:gravity="center"
android:text="Start" />
<Button
android:id="@+id/btn_about"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_start"
android:layout_below="@+id/btn_start"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="About me" />
<Button
android:id="@+id/btn_exit"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Button01"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dp"
android:gravity="center"
android:text="Exit" />
</RelativeLayout>