Caused by: java.lang.ClassCastException: org.winplus.sufing.SecoandActivity
最好把这个activity贴出来!
最好把这个activity贴出来!
解决方案 »
- android apk包加密
- android实现动态人脸识别
- 监听短信的receiver 一直好好的,突然报下面那个错。
- 请教:卸载程序的时候怎么同时把widget自动删除呢?
- layout的setWeightSum函数该怎么使用?
- conn.setRequestMethod("GET") 异常
- 准备写个手机地图浏览程序,纠结中,各位路过的帮忙分析分析!!!
- 桌面电脑上的红帽Linux 和 嵌入式Linux 的问题
- 关于SQLite的问题
- android是如何操作网络数据库,有那些方法以?大侠们讲解下
- 删除listview其中一个列表项,下面的列表项向上移动的效果要怎么实现??
- 求救!!!安装repo老是出这样的错误
从代码层面来看是运行到了SecoandActivity.java第35行,有错,停止运行的。
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;public class SecoandActivity extends Activity {
public static final String DB_NAME="My.db";
public static final int VERSION=1;
public MyHelper helper;
public SQLiteDatabase mydb;
private Spinner mySpinner;
private ArrayAdapter<String> adapter1;
private Button button1,button2,button3,button4,button5,button6;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secoand);
button1=(Button)this.findViewById(R.id.button1);
button2=(Button)this.findViewById(R.id.button2);
button3=(Button)this.findViewById(R.id.button3);
button4=(Button)this.findViewById(R.id.button4);
button5=(Button)this.findViewById(R.id.button5);
button6=(Button)this.findViewById(R.id.button6);
mySpinner=(Spinner)this.findViewById(R.id.spinner1);
button1.setOnClickListener((OnClickListener) this);
button2.setOnClickListener((OnClickListener) this);
button3.setOnClickListener((OnClickListener) this);
button4.setOnClickListener((OnClickListener) this);
button5.setOnClickListener((OnClickListener) this);
button6.setOnClickListener((OnClickListener) this);
//初始化数据库辅助对象
helper=new MyHelper(this, DB_NAME, null, VERSION);
try {
//获取可读写的SQLiteDatabase对象
mydb=helper.getWritableDatabase();
CreateTable();
} catch (SQLiteException e) {
// TODO: handle exception
mydb=helper.getReadableDatabase();
e.printStackTrace();
}
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.secoand, menu);
return true;
}
public void onClick(View v)
{
if(v==button1)//插入两条记录
{
InsertData();
}
else if(v==button2)//删除一条记录
{
DeleteData();
}
else if(v==button3)//修改记录
{
ModifyData();
}
else if(v==button4)//删除数据表
{
DeleteTable();
}
else if(v==button5)//查询数据库
{
QueryData();
}
else if(v==button6)//重建数据库
{
CreateTable();
}
}
void InsertData()
{
ContentValues values=new ContentValues();
values.put(helper.ID, 1);
values.put(helper.NAME, "孙刚");
values.put(helper.HEIGHT, 1.75);
mydb.insert(helper.TB_NAME, null, values);
mydb.execSQL("insert into studenttable(id,name,height) values(2,'张超',1.80)");
UpdateSpinner();
}
void UpdateSpinner()
{
QueryData();
}
void DeleteData()
{
mydb.delete(helper.TB_NAME, helper.ID, null);
UpdateSpinner();
}
void ModifyData()
{
ContentValues values=new ContentValues();
values.put(helper.NAME, "张华");
values.put(helper.HEIGHT, 1.60);
mydb.update(helper.TB_NAME, values, helper.ID, null);
UpdateSpinner();
}
void DeleteTable()
{
mydb.execSQL("DROP TABLE IF EXISTS"+helper.TB_NAME);
UpdateSpinner();
}
void CreateTable()
{
mydb.execSQL("CREATE TABLE IF NOT EXISTS"+helper.TB_NAME+"("+helper.ID+"integer primary key,"+helper.NAME+"text,"+helper.HEIGHT+"float)");
UpdateSpinner();
}
void QueryData()
{
adapter1=null;
mySpinner.setAdapter(adapter1);
Cursor result=mydb.query(false,"studenttable", null, null, null, null, null, null, null, null);
int count=result.getCount();
if(count==0)return;
String[] Str=new String[count];
result.moveToFirst();int i=0;
while(!result.isAfterLast())
{
int id=result.getInt(0);
String name=result.getString(1);
float height=result.getInt(2);
Str[i]=String.valueOf(id)+""+name+""+String.valueOf(height);
i++;
result.moveToNext();
}
result.close();
adapter1=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,Str);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_item);
//将adapter添加到spinner对象中
mySpinner.setAdapter(adapter1);
}
@Override
public void onDestroy()
{
if(mydb!=null)
{
mydb.close();
mydb=null;
}
super.onDestroy();
}
}