我是直接跟别人代码里一样写的,但到了我自己的项目里就无法实现活动跳转,程序报错自动关闭了,
求大神帮忙看看错在哪里了
package com.example.re;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
//import java.io.InputStream;
import com.example.eluosifangkuai.R;
import com.example.re.SQLiteHelper;
public class RankActivity extends Activity {
private View m_view;
private TextView m_textview_ranking_num;
private TextView m_textview_ranking_name;
private TextView m_textview_ranking_score;
private TextView m_textview_ranking_date;
private SQLiteHelper m_SqLiteHelper = new SQLiteHelper(this);
private SQLiteDatabase m_SQLiteDatabase;
//@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ranking);
m_view=(View)findViewById(R.id.RankingActivity) ;
m_textview_ranking_num=(TextView)findViewById(R.id.textview_ranking1);
m_textview_ranking_name=(TextView)findViewById(R.id.textview_ranking2);
m_textview_ranking_score=(TextView)findViewById(R.id.textview_ranking3);
m_textview_ranking_date=(TextView)findViewById(R.id.textview_ranking4);
m_SQLiteDatabase = m_SqLiteHelper.getWritableDatabase();
}
//@Override
protected void onStart() {
// TODO Auto-generated method stub
int num=0;
String str;
// LoadBkGd();
m_textview_ranking_num.setText("");
m_textview_ranking_name.setText("");
m_textview_ranking_score.setText("");
m_textview_ranking_date.setText("");
String _SqlText = "Select * From ranking order by Score desc";
Cursor _CursorB = m_SQLiteDatabase.rawQuery(_SqlText, null);
while (_CursorB.moveToNext()) {
num++;
m_textview_ranking_num.setText(m_textview_ranking_num.getText().toString()+num+"\n");
str=_CursorB.getString(_CursorB.getColumnIndex("UserName"))+"\n";
m_textview_ranking_name.setText(m_textview_ranking_name.getText().toString()+str);
str=_CursorB.getInt(_CursorB.getColumnIndex("Score"))+"\n";
m_textview_ranking_score.setText(m_textview_ranking_score.getText().toString()+str);
str=_CursorB.getString(_CursorB.getColumnIndex("Date"))+"\n";
m_textview_ranking_date.setText(m_textview_ranking_date.getText().toString()+str);
}
super.onStart();
}
}
package com.example.re;
import com.example.re.DateBaseConfig;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class SQLiteHelper extends SQLiteOpenHelper {
private static final String m_DataBaseName = "infDateBase";
private static final int m_Version = 1;
public SQLiteHelper(Context context)
{
// 创建一个名为GetDataBaseName的数据库
super(context, GetDataBaseName(), null, GetVersion());
}
@Override
public void onCreate(SQLiteDatabase arg0) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
public void Init(SQLiteDatabase arg0)
{
String _SqlText ="Select * From sqlite_master Where type = 'table' AND name='ranking'" ;
Cursor _Cursor =arg0.rawQuery(_SqlText, null) ;
//Log.i("你好","有表");
if(_Cursor.getCount()==0)
{
//Log.i("你好","没ranking表");
_SqlText="Create TABLE ranking([UserName] varchar(10) NOT NULL,[Score] integer NOT NULL" +
",[Date] varchar(50) NOT NULL)" ;
arg0.execSQL(_SqlText);
//Date _date=new Date();
ContentValues _ContentValues = new ContentValues();
_ContentValues.put("UserName","mYI");
_ContentValues.put("Score",1);
//SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
_ContentValues.put("Date","2013年10月1日");
arg0.insert("ranking", null, _ContentValues);
}
}
public static String GetDataBaseName() {
return m_DataBaseName;
}
public static int GetVersion() {
return m_Version;
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。