android初学小菜 我遇到一个问题 高手来帮忙

sike200008 2010-09-11 10:43:34
package com.show1;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RadioButton;
import android.widget.TextView;
public class show1 extends Activity {
/** Called when the activity is first created. */
public RadioGroup RadGroup;
public RadioButton RadBtn1,RadBtn2;
public TextView text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RadGroup=(RadioGroup)findViewById(R.id.RadGroup);
RadBtn1=(RadioButton)findViewById(R.id.Rad1);
RadBtn2=(RadioButton)findViewById(R.id.Rad2);
text=(TextView)findViewById(R.id.text);
RadGroup.setOnCheckedChangeListener(mChangeRadio);
}

private RadioGroup.OnCheckedChangeListener mChangeRadio=new RadioGroup.OnCheckedChangeListener() {

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if(checkedId==RadBtn1.getId())
{
text.setText(RadBtn1.getText());
}
else
{
text.setText(RadBtn2.getText());
}
}
};
}
我写的一个小代码 一运行就崩溃 请问哪里有错误? 我实在是找不出来了
...全文
117 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ameyume 2010-09-12
  • 打赏
  • 举报
回复
楼主的代码完全正确,没有任何问题。
我把楼主的代码拷贝后,自己完善了main.xml后,运行正常。建议楼主重新建一个工程试试。
我的main.xml如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:id="@+id/text"
/>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/RadGroup"
>
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="On"
android:id="@+id/Rad1"
/>
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Off"
android:id="@+id/Rad2"
/>
</RadioGroup>
</LinearLayout>
crazylittle 2010-09-12
  • 打赏
  • 举报
回复
为什么不把异常信息贴出来?
「已注销」 2010-09-12
  • 打赏
  • 举报
回复
有时候模拟器也会出现诡异的错误,重启下看看
yyy025025025 2010-09-11
  • 打赏
  • 举报
回复
把androidmanifest.xml和main.xml都贴上来看下~

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧