为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我的在虚拟机运行后出现应用程序停止运行

package com.example.sss;


import com.example.android4_0.R;


import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.CompoundButton;

import android.widget.EditText;

import android.widget.ImageButton;

import android.widget.Toast;

import android.widget.ToggleButton;

import android.widget.CompoundButton.OnCheckedChangeListener;


public class MainActivity extends Activity implements OnCheckedChangeListener{

/*

 *类属性确定一个控件

 *

 */

private ToggleButton tb;

private ImageButton img;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//引入布局文件

setContentView(R.layout.activity_main);

tb=(ToggleButton) findViewById(R.id.toggleButton1);

img=(ImageButton)findViewById(R.id.imageView1);

tb.setOnCheckedChangeListener(this);



}


@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}


@Override

public boolean onOptionsItemSelected(MenuItem item) {

// Handle action bar item clicks here. The action bar will

// automatically handle clicks on the Home/Up button, so long

// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();

if (id == R.id.action_settings) {

return true;

}

return super.onOptionsItemSelected(item);

}


@Override

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

img.setBackgroundResource(isChecked?R.drawable.on:R.drawable.off);

}


}


正在回答

1 回答

我也出现了这个问题

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Android攻城狮的第一门课(入门篇)
  • 参与学习       312636    人
  • 解答问题       4633    个

想快速掌握Android应用开发基础,选择学习这门课程就对了。

进入课程

为什么我的在虚拟机运行后出现应用程序停止运行

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信