开发者社区> 问答> 正文

急!android编写高分榜Activity因为SQLite无法实现跳转,求大神找错

我是直接跟别人代码里一样写的,但到了我自己的项目里就无法实现活动跳转,程序报错自动关闭了,
求大神帮忙看看错在哪里了

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;
}



}

展开
收起
a123456678 2016-07-18 15:30:33 2042 0
1 条回答
写回答
取消 提交回答
  • 找到了,太傻了 漏了一句这个
    m_SqLiteHelper.Init(m_SQLiteDatabase);

    2019-07-17 19:57:58
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载