我剛做了這個應用程序,它在按鈕單擊時崩潰... 不知道爲什麼... 到目前爲止,這應該打印1,如果選擇1和2如果2,和等等。 這是main.xml和Activity.java文件。應用程序崩潰在按鈕點擊
This is Main.xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/spinnerprompt"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Spinner
android:id="@+id/Spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinnerprompt" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/buttontext"
android:onClick="onClick"/>
<FrameLayout
android:id="@+id/frameLayout1"
android:layout_width="match_parent"
android:layout_height="30dp" >
</FrameLayout>
<TextView
android:id="@+id/versetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
And Activity.java file
package arirang.today.proverbs;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class TodaysProverbsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner Spinner1 = (Spinner) findViewById(R.id.Spinner1);
ArrayAdapter adapter1 = ArrayAdapter.createFromResource(
this, R.array.datelist, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner1.setAdapter(adapter1);
}
public void onclick(View view){
Spinner Type;
String verse = "";
Type = (Spinner)findViewById(R.id.Spinner1);
if(Type.getSelectedItem().toString().equals("1")){
verse = "1";
}
if(Type.getSelectedItem().toString().equals("2")){
verse = "2";
}
if(Type.getSelectedItem().toString().equals("3")){
verse = "3";
}
if(Type.getSelectedItem().toString().equals("4")){
verse = "4";
}
if(Type.getSelectedItem().toString().equals("5")){
verse = "5";
}
if(Type.getSelectedItem().toString().equals("6")){
verse = "6";
}
if(Type.getSelectedItem().toString().equals("7")){
verse = "7";
}
if(Type.getSelectedItem().toString().equals("8")){
verse = "8";
}
if(Type.getSelectedItem().toString().equals("9")){
verse = "9";
}
if(Type.getSelectedItem().toString().equals("10")){
verse = "10";
}
if(Type.getSelectedItem().toString().equals("11")){
verse = "11";
}
if(Type.getSelectedItem().toString().equals("12")){
verse = "12";
}
if(Type.getSelectedItem().toString().equals("13")){
verse = "13";
}
if(Type.getSelectedItem().toString().equals("14")){
verse = "14";
}
if(Type.getSelectedItem().toString().equals("15")){
verse = "15";
}
if(Type.getSelectedItem().toString().equals("16")){
verse = "16";
}
if(Type.getSelectedItem().toString().equals("17")){
verse = "17";
}
if(Type.getSelectedItem().toString().equals("18")){
verse = "18";
}
if(Type.getSelectedItem().toString().equals("19")){
verse = "19";
}
if(Type.getSelectedItem().toString().equals("20")){
verse = "20";
}
if(Type.getSelectedItem().toString().equals("21")){
verse = "21";
}
if(Type.getSelectedItem().toString().equals("22")){
verse = "22";
}
if(Type.getSelectedItem().toString().equals("23")){
verse = "23";
}
if(Type.getSelectedItem().toString().equals("24")){
verse = "24";
}
if(Type.getSelectedItem().toString().equals("25")){
verse = "25";
}
if(Type.getSelectedItem().toString().equals("26")){
verse = "26";
}
if(Type.getSelectedItem().toString().equals("27")){
verse = "27";
}
if(Type.getSelectedItem().toString().equals("28")){
verse = "28";
}
if(Type.getSelectedItem().toString().equals("29")){
verse = "29";
}
if(Type.getSelectedItem().toString().equals("30")){
verse = "30";
}
if(Type.getSelectedItem().toString().equals("31")){
verse = "31";
}
TextView AfterBox = (TextView)findViewById(R.id.versetext);
AfterBox.setText(verse);
}
}
感謝您的閱讀,這不是短... ^^
什麼是logcat消息? – kosa 2012-02-11 04:38:09
粘貼日誌以查看確切概率 – jeet 2012-02-11 04:42:11
equals「將指定的對象與此字符串進行比較,如果相等,則返回true。對象必須是具有相同順序的相同字符的字符串實例」,請嘗試使用匹配項「測試是否爲此字符串匹配給定的regularExpression。「 – 2012-02-11 05:08:05