Androidstudio编译的apk一运行就显示停止运行 - 爱问答

(爱问答)

Androidstudio编译的apk一运行就显示停止运行

public class MainActivity extends AppCompatActivity {   

 private Button b1 = (Button)findViewById(R.id.buttonTop);   

 private Button b2 = (Button)findViewById(R.id.buttonBottom);    

private TextView t = (TextView)findViewById(R.id.storyTextView);    

@Override    

protected void onCreate(Bundle savedInstanceState) {        

super.onCreate(savedInstanceState);        

setContentView(R.layout.activity_main);        

b1.setOnClickListener(new View.OnClickListener() {            

@Override            public void onClick(View view) {                

b1.setText(R.string.s1a1);               

 b2.setText(R.string.s1a2);               

 t.setText(R.string.s1);           

 }        });        

b2.setOnClickListener(new View.OnClickListener() {           

 @Override            public void onClick(View view) {               

 b1.setText(R.string.s2a1);               

 b2.setText(R.string.s2a2);               

 t.setText(R.string.s2);           

 }        });   

 }}

是顺序有错误引起的。

修改两个地方:

(1)将以下三句:

private Button b1 = (Button)findViewById(R.id.buttonTop);  

private Button b2 = (Button)findViewById(R.id.buttonBottom);   

private TextView t = (TextView)findViewById(R.id.storyTextView);   

 修改为:

private Button b1;

private Button b2; 

private TextView t;

(2)

在语句:setContentView(R.layout.activity_main);    的后面,

增加以下三个语句:

b1 = (Button)findViewById(R.id.buttonTop);

b2 = (Button)findViewById(R.id.buttonBottom);   

t = (TextView)findViewById(R.id.storyTextView);   

相关标签:apk

下一篇:图中的男如何

上一篇:这几款CPU那个超频体质或者性能比较好?

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?