當我按下我的應用程序中的「開始活動」按鈕它將無法正常工作,並被迫停止工作。不幸的應用程序停止工作
這是第一個XML文件(get.xml):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/etget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Enter Your Gender" />
<Button
android:id="@+id/bget1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/etget"
android:text="Start Activity" />
<Button
android:id="@+id/bget2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/etget"
android:layout_toLeftOf="@id/bget1"
android:text="Start Activity for Result " />
<TextView
android:id="@+id/tvget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/bget2"
android:text="TextView" />
</RelativeLayout>
下面是Java文件,Get.java:
package example.katta;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Get extends Activity implements OnClickListener {
Button bg1, bg2;
TextView tv;
TextView etg;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.get);
etg = (TextView) findViewById(R.id.etget);
bg1 = (Button) findViewById(R.id.bget1);
bg2 = (Button) findViewById(R.id.bget2);
tv = (TextView) findViewById(R.id.tvget);
bg1.setOnClickListener(this);
bg2.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()) {
case R.id.bget1:
String bread = etg.getText().toString();
Bundle basket = new Bundle();
basket.putString("key", bread);
Intent a = new Intent(Get.this, Send.class);
a.putExtras(basket);
startActivity(a);
break;
case R.id.bget2:
break;
}
}
}
這裏是第二屆XML文件(send.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/etsend"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TextView>
<RadioGroup
android:id="@+id/rgsend"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rb1send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="@+id/rb2send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
<TextView
android:id="@+id/tvsend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="@+id/buttonsend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
這裏是Java文件(Send.java):
package example.katta;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class Send extends Activity implements OnClickListener, OnCheckedChangeListener {
Button bts;
TextView tvs,ets;
RadioGroup selection;
String gotbread;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.send);
Initialize();
Bundle gotbasket = getIntent().getExtras();
gotbread = gotbasket.getString("key");
tvs.setText(gotbread);
}
private void Initialize() {
// TODO Auto-generated method stub
ets = (TextView) findViewById(R.id.etsend);
bts = (Button) findViewById(R.id.buttonsend);
tvs = (TextView) findViewById(R.id.tvsend);
selection = (RadioGroup) findViewById(R.id.rgsend);
bts.setOnClickListener(this);
selection.setOnCheckedChangeListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
switch (arg1) {
case R.id.rb1send:
break;
case R.id.rb2send:
break;
}
}
}
添加堆棧跟蹤請 –
logcat跟蹤? – Rakesh
是的,裏面有錯誤信息。 –