我是直接跟別人代碼裡一樣寫的,但到了我自己的項目裡就無法實現活動跳轉,程序報錯自動關閉了,
求大神幫忙看看錯在哪裡了
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;
}
}
找到了,太傻了 漏了一句這個
m_SqLiteHelper.Init(m_SQLiteDatabase);