我有一個使用IntelliJ 12社區版IDE的Android程序。我需要在使用按鈕創建的不同佈局(.xml)之間導航。但是,每當我使用模擬器運行它時,它只會打開main.xml屏幕,每當我點擊按鈕時,它會說:「不幸的是,ITax已停止工作。」多個佈局Android應用程序
這是我的MyActivity.java類代碼:
package com.example.ITax;
import android.app.Activity;
import android.content.Intent;
android.os.Bundle;
android.view.View;
import android.widget.Button;
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button1 = (Button)findViewById(R.id.btn_info);
Button button2 = (Button)findViewById(R.id.btn_tutorial);
Button button3 = (Button)findViewById(R.id.btn_calc);
Button button4 = (Button)findViewById(R.id.btn_back_from_calcu);
Button button5 = (Button)findViewById(R.id.btn_next_from_calcu);
Button button6 = (Button)findViewById(R.id.btn_back_from_monthlyorannual);
Button button7 = (Button)findViewById(R.id.btn_next_from_monthlyorannual);
Button button8 = (Button)findViewById(R.id.btn_back_from_civilstatus);
Button button9 = (Button)findViewById(R.id.btn_next_from_civilstatus);
Button button10 = (Button)findViewById(R.id.btn_back_from_inputamount_monthly);
Button button11 = (Button)findViewById(R.id.btn_compute_from_monthly);
Button button12 = (Button)findViewById(R.id.btn_back_from_outputamount_monthly);
Button button13 = (Button)findViewById(R.id.btn_home_from_outputamount_monthly);
}
public void Open_BasicInfo()
{
Intent i = new Intent(this, OpenBasicInfo.class);
startActivity(i);
}
public void Open_Tutorial()
{
Intent i = new Intent(this, OpenTutorial.class);
startActivity(i);
}
public void Open_Calculator()
{
Intent i = new Intent(this, OpenCalculator.class);
startActivity(i);
}
public void Open_MonthlyOrAnnually()
{
Intent i = new Intent(this, OpenMonthlyOrAnnually.class);
startActivity(i);
}
public void Open_CivilStatus()
{
Intent i = new Intent(this, OpenCivilStatus.class);
startActivity(i);
}
public void Open_InputAmountsFromMonthly()
{
Intent i = new Intent(this, OpenInputAmountsFromMonthly.class);
startActivity(i);
}
public void Open_OutputAmountsFromMonthly()
{
Intent i = new Intent(this, OutputAmountsFromMonthly.class);
startActivity(i);
}
public void Open_Main()
{
Intent i = new Intent(this, MyActivity.class);
startActivity(i);
}
}
我已經創建了一個類爲每個佈局而在Android的manifest聲明是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ITax"
android:versionCode="1"
android:versionName="ITax 1.0">
<uses-sdk android:minSdkVersion="1"/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name=".MyActivity"
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=".OpenCalculator">
</activity>
<activity android:name=".OpenCivilStatus">
</activity>
<activity android:name=".OpenInputAmountsFromMonthly">
</activity>
<activity android:name=".OutputAmountsFromMonthly">
</activity>
<activity android:name=".OpenTutorial">
</activity>
<activity android:name=".OpenBasicInfo">
</activity>
<activity android:name=".OpenMonthlyOrAnnually">
</activity>
<activity android:name=".OpenMain">
</activity>
</application>
</manifest>
我已經把在所有按鈕中都使用android:onClick =「name of method」。
幫助!我在這裏做了什麼似乎是錯誤的? :(
我在模擬器應用程序停止工作時,我已經點擊的按鈕> <
你有沒有在按鈕上應用onclicklistener? – Ashwani
哦,是的!但是每當我在MyActvity.Java中的代碼中包含其他佈局的按鈕時,我就使用模擬器運行它,它也停止工作。 –
還是謝謝你的回答!^___^ –