初学者自写的程序 ,但是在模拟器下运行闪退!!该怎么改呀??
package com.example.work3;
import java.util.ArrayList;
import java.util.List;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.TextView;
import android.os.Build;
public class MainActivity extends TabActivity {
private TabHost tabhost;
private ListView listview;
private ArrayAdapter arr_adapter;
private Spinner spinner;
private Listlist;
private ArrayAdapter adapter;
private EditText et1,et2;
private Button bt;
String name;
String value;
String style;
@SuppressLint("NewApi") @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
et1=(EditText) findViewById(R.id.editText1);
et2=(EditText) findViewById(R.id.editText2);
bt=(Button) findViewById(R.id.button1);
setContentView(R.layout.activity_main);
tabhost=getTabHost();
tabhost.addTab(tabhost.newTabSpec("菜单一").setIndicator("首页").setContent(R.id.tab1));
tabhost.addTab(tabhost.newTabSpec("菜单二").setIndicator("新增").setContent(R.id.tab2));
tabhost.addTab(tabhost.newTabSpec("菜单三").setIndicator("账单").setContent(R.id.tab3));
//按钮监听 提取信息
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
name = et1.getText().toString();
value = et2.getText().toString();
style = spinner.getSelectedItem().toString();
}
});
listview = (ListView) findViewById(R.id.listview);
//新建适配器
String[]arr_data={"数据1","数据2","数据3","数据4","数据5"};
//ArrayAdapter(上下文,当前ListView加载的每一个列表项所对应的布局文件,数据源)
arr_adapter =new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,arr_data);
listview.setAdapter(arr_adapter);
spinner=(Spinner) findViewById(R.id.spinner);
//数据源
String[]list = {"1.日常食品支出","2.人情世故支出","3.出差旅游支出","4.服饰鞋帽支出","5.生活用品支出","6.其他支出"};
//新建适配器
adapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
//设置下拉样式
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//加载适配器
spinner.setAdapter(adapter);
}
//退出对话框
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK )
{
// 创建退出对话框
AlertDialog isExit = new AlertDialog.Builder(this).create();
// 设置对话框标题
isExit.setTitle("系统提示");
// 设置对话框消息
isExit.setMessage("确定要退出吗");
// 添加选择按钮并注册监听
isExit.setButton("确定", listener);
isExit.setButton2("取消", listener);
// 显示对话框
isExit.show();
}
return false;
}
/**监听对话框里面的button点击事件*/
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
switch (which)
{
case AlertDialog.BUTTON_POSITIVE:// "确认"按钮退出程序
finish();
break;
case AlertDialog.BUTTON_NEGATIVE:// "取消"第二个按钮取消对话框
break;
default:
break;
}
}
};
}