Android SQLite警告

时间:2016-11-30 11:33:16

标签: java android sqlite

我在SQLite中有一些奇怪的警告。 这是什么意思?

  

11-30 13:05:23.653 9964-9964 / com.hikari.dev.servermonitor   D / SQLiteDatabase:打开数据库       java.lang.Throwable:stacktrace           在android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:815)           在android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:714)           在android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:578)           在android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:269)           在android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)           在android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)         - >在com.hikari.dev.servermonitor.main.onClick(main.java:40)           在android.view.View.performClick(View.java:5269)           在android.view.View $ PerformClick.run(View.java:21556)           在android.os.Handler.handleCallback(Handler.java:815)           在android.os.Handler.dispatchMessage(Handler.java:104)           在android.os.Looper.loop(Looper.java:207)           在android.app.ActivityThread.main(ActivityThread.java:5769)           at java.lang.reflect.Method.invoke(Native Method)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

database_helper.java(singleton)

package com.hikari.dev.servermonitor;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class database_helper extends SQLiteOpenHelper
{
    // Database
    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "ServerMonitorDatabase";
    public static final String TABLE_SERVERS = "servers";

//Servers
public static final String SERVER_ID = "_id";
public static final String SERVER_NAME = "name";
public static final String SERVER_MONITORING_STATUS = "monitoring_status";
public static final String SERVER_IP = "ip";
public static final String SERVER_PORT = "port";

//Singleton
private static database_helper instance;

public static database_helper getInstance(Context context)
{
    if(instance == null)
        instance = new database_helper(context.getApplicationContext());
    return instance;
}

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase)
{
    sqLiteDatabase.execSQL("create table " + TABLE_SERVERS + "(" + SERVER_ID
            + " integer primary key," + SERVER_NAME  + " text," + SERVER_MONITORING_STATUS
            + " integer," + SERVER_IP + " text," + SERVER_PORT + " integer)");
}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1)
{
    sqLiteDatabase.execSQL("drop table if exists" + TABLE_SERVERS);

    onCreate(sqLiteDatabase);
}

private database_helper(Context context)
{
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}


}

main.java

(40)    SQLiteDatabase database = database_helper.getInstance(this).getReadableDatabase();

1 个答案:

答案 0 :(得分:0)

这里我在特定位置创建DATABASE:

MessageLocalDB msgDB;



String LocalDBMesage ="_chatdb.db";
        String FinalLocalDBName = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + LocalDBMesage;
        msgDB= MessageLocalDB.getInstance(MainActivity.this,FinalLocalDBName);

在活动中:

msgDB.insertMSG(strSr,strenquiryID,"2323","DIvyesh",currentMSG,fdfg,msgStatus);

将数据写入数据库,如:

Cursor count=msgDB.fetchMSG(Integer.parseInt(strenquiryID));

读取数据:

{{1}}