Android Studio 调试出现“很抱歉,XXX已停止运行”,可代码没报错

weixin_44150729 2019-04-09 10:42:48
package com.example.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private TextView mTxtComPlay,mTxtResult;
private Button mBtnScissors,mBtnStone,mBtnPaper;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.menu.main);

mTxtComPlay=(TextView)findViewById(R.id.txtComPlay);
mTxtResult=(TextView)findViewById(R.id.txtResult);
mBtnScissors=(Button)findViewById(R.id.btnScissors);
mBtnStone=(Button)findViewById(R.id.btnStone);
mBtnPaper=(Button)findViewById(R.id.btnPaper);

mBtnScissors.setOnClickListener(btnScissorsOnClick);
mBtnStone.setOnClickListener(btnStoneOnClick);
mBtnPaper.setOnClickListener(btnPaperOnClick);
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.main,menu);
return true;
}

private Button.OnClickListener btnScissorsOnClick=new Button.OnClickListener(){
public void onClick(View v){
int iComPlay=(int)(Math.random()*3+1);
if (iComPlay==1){
mTxtComPlay.setText(R.string.play_scissors);
mTxtResult.setText(getString(R.string.result)+getString(R.string.player_draw));
}
else if (iComPlay==2){
mTxtComPlay.setText(R.string.play_stone);
mTxtResult.setText(getString(R.string.result)+getString(R.string.player_lose));
}
else {
mTxtComPlay.setText(R.string.play_paper);
mTxtResult.setText(getString(R.string.result)+getString(R.string.player_win));
}
}
};

private Button.OnClickListener btnStoneOnClick=new Button.OnClickListener(){
public void onClick(View v){
int iComPlay=(int)(Math.random()*3+1);
if (iComPlay==1){
mTxtComPlay.setText(R.string.play_scissors);
mTxtResult.setText(getString(R.string.result)+getString(R.string.player_win));
}
else if (iComPlay==2){
mTxtComPlay.setText(R.string.play_stone);
mTxtResult.setText(getString(R.string.result)+getString(R.string.player_draw));
}
else {
mTxtComPlay.setText(R.string.play_paper);
mTxtResult.setText(getString(R.string.result)+getString(R.string.player_lose));
}
}
};

private View.OnClickListener btnPaperOnClick=new View.OnClickListener() {
@Override
public void onClick(View v) {
int iComPlay=(int)(Math.random()*3+1);
if (iComPlay==1){
mTxtComPlay.setText(R.string.play_scissors);
mTxtResult.setText(getString(R.string.result)+getString(R.string.player_lose));
}
else if (iComPlay==2){
mTxtComPlay.setText(R.string.play_stone);
mTxtResult.setText(getString(R.string.result)+getString(R.string.player_win));
}
else {
mTxtComPlay.setText(R.string.play_paper);
mTxtResult.setText(getString(R.string.result)+getString(R.string.player_draw));
}
}
};
///
}
...全文
3882 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
usecf 2019-04-15
  • 打赏
  • 举报
回复
搜fatal关键字,抓logcat的log
weixin_44380190 2019-04-12
  • 打赏
  • 举报
回复
可能你的某个线程操作的变量没有去初始化之类
「已注销」 2019-04-11
  • 打赏
  • 举报
回复
代码不报错不代表程序没有错误,多半是引用为空直接调用方法了
耿耿27 2019-04-11
  • 打赏
  • 举报
回复
查看一下logcat 上边会告诉你哪里的程序有错误
不会爬树 应用层 2019-04-11
  • 打赏
  • 举报
回复
android studio不是有debug模式吗?会用吗?查一查,很好用的,然后你随便打开一个xml,然后打开 看看有没有预览,还是显示preview is unavailable until a successful build 如果显示不出来,就clean project 一下,如果还没显示 ↓ https://blog.csdn.net/cantclimbthetree/article/details/89202601
王能 2019-04-11
  • 打赏
  • 举报
回复
新人贴,先看完再来提问吧:https://blog.csdn.net/weimingjue/article/details/87921494
fei得更高 2019-04-10
  • 打赏
  • 举报
回复
可能你的某个线程操作的变量没有去初始化之类的
丶Chao 2019-04-09
  • 打赏
  • 举报
回复
调试异常中断,log里应该有报错吧
jzp12 2019-04-09
  • 打赏
  • 举报
回复
怎么调用2次setContentView?
jzp12 2019-04-09
  • 打赏
  • 举报
回复
看一下crash堆栈

80,337

社区成员

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

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