我認爲我的活動存在問題,因爲它運行的啓動畫面很好,但是當它到達主頁時,它會給出強制關閉錯誤。我也很感激,如果你能看到我的home.java
代碼是否正確我基本上想打開其他活動和退出按鈕來退出應用程序。爲什麼我的活動不開始?
Android清單
<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>
home.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
}
}
String.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>
home.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>
您是否在啓動時從家庭活動調用startActivity()? – xordon
安置自己的logcat跟蹤,看看錯誤 –
寫<活動 機器人:名字=「首頁‘/>而不是<活動 機器人:名字=’首頁」 機器人:標籤=‘@字符串/ title_activity_home’> intent-filter> 併發布你的logcat –