程序停止运行

luluanzhongtu98 2016-04-05 11:15:55
刚刚学安卓不就,好几次程序代码都没有报错,可是为什么每次连接手机运行的时候就提示程序停止运行。就像这次又出现了,下面是代码和报错:
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;

public class MainActivity extends Activity {
private RadioButton radioButtonA;
private RadioButton radioButtonB;
private RadioButton radioButtonC;
private RadioButton radioButtonD;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioButtonA = (RadioButton) findViewById(R.id.radioButtonA);
radioButtonB = (RadioButton) findViewById(R.id.radioButtonB);
radioButtonC = (RadioButton) findViewById(R.id.radioButtonC);
radioButtonD = (RadioButton) findViewById(R.id.radioButtonD);
RadioCheckedListener listener = new RadioCheckedListener();
radioButtonA.setOnCheckedChangeListener(listener);
}

class RadioCheckedListener implements OnCheckedChangeListener{

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
radioButtonC.setChecked(true);
}
else{
radioButtonC.setChecked(false);
}
}

}
...全文
167 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ganshenml 2016-04-06
  • 打赏
  • 举报
回复
使用了你的代码在真机上运行了一下,是没有报错的。 将你在真机上运行的结果错误日志打出来看看。
ESC尛蜜蜂 2016-04-06
  • 打赏
  • 举报
回复
报错在哪? 布局文件看看
luluanzhongtu98 2016-04-06
  • 打赏
  • 举报
回复
问题得以解决了,谢谢大家的帮助
lx912356858 2016-04-06
  • 打赏
  • 举报
回复
引用 6 楼 luluanzhongtu98 的回复:
[quote=引用 3 楼 lx912356858 的回复:] 建议 下次出错先看log日志 从那里挑着看代码 会事半功倍的
应该怎么看logcat哦,,里面感觉好多东西。。[/quote] 一般看log 先找Caused by:。。。。。 这是告诉你错误是啥 然后双击它底下那行 就会跳到你代码错误的地方 如果不行的话 你就按个红字的都双击点点 总有一个会跳到错误的地方
ganshenml 2016-04-06
  • 打赏
  • 举报
回复
Caused by : you must supply a layout_width attribute layout配置文件中没给控件指定“ layout_width ”这个属性
luluanzhongtu98 2016-04-06
  • 打赏
  • 举报
回复
引用 3 楼 lx912356858 的回复:
建议 下次出错先看log日志 从那里挑着看代码 会事半功倍的
应该怎么看logcat哦,,里面感觉好多东西。。
luluanzhongtu98 2016-04-06
  • 打赏
  • 举报
回复
引用 1 楼 a511341250 的回复:
报错在哪? 布局文件看看
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.hwradio.MainActivity" > <RadioButton android:id="@+id/radioButtonA" /> <RadioButton android:id="@+id/radioButtonB" /> <RadioButton android:id="@+id/radioButtonC" /> <RadioButton android:id="@+id/radioButtonD" /> </LinearLayout> 这个就是布局文件,麻烦了。。
luluanzhongtu98 2016-04-06
  • 打赏
  • 举报
回复
引用 2 楼 ganshenml 的回复:
使用了你的代码在真机上运行了一下,是没有报错的。
将你在真机上运行的结果错误日志打出来看看。


这个就是报错,昨天一直上传不了,麻烦了。。
lx912356858 2016-04-06
  • 打赏
  • 举报
回复
建议 下次出错先看log日志 从那里挑着看代码 会事半功倍的

80,351

社区成员

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

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