Android SQL数据库文件未显示

时间:2017-11-13 06:04:29

标签: javascript android sql

我正在开发一个类的应用程序,该应用程序将使用SQL数据库来跟踪距离并不断更新它们。我以前从未在java中编码或实现过SQL数据库,所以我遇到了一些问题。现在我试图用初始值(0)加载我的数据库,但数据库文件不会弹出设备监视器,请帮忙!



package tamu.thecaddyapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;


public class MainActivity extends AppCompatActivity {

    Button buttonDriver, buttonFouriron, buttonFiveiron, buttonSixiron, buttonSeveniron, buttonEightiron, buttonNineiron, buttonPW, buttonFiftysix, buttonSW, buttonSixty;
    DataHandler helper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        buttonDriver = (Button)findViewById(R.id.button_DRIVER);
        buttonFouriron = (Button)findViewById(R.id.button_4IRON);
        buttonFiveiron = (Button)findViewById(R.id.button_5IRON);
        buttonSixiron = (Button)findViewById(R.id.button_6IRON);
        buttonSeveniron = (Button)findViewById(R.id.button_7IRON);
        buttonEightiron = (Button)findViewById(R.id.button_8IRON);
        buttonNineiron = (Button)findViewById(R.id.button_9IRON);
        buttonPW = (Button)findViewById(R.id.button_PW);
        buttonSW = (Button)findViewById(R.id.button_SW);
        buttonFiftysix = (Button)findViewById(R.id.button_56DEG);
        buttonSixty = (Button)findViewById(R.id.button_60DEG);
    }

    public void buttonDriver(View view) {
    }

    public void buttonFouriron(View view) {
    }

    public void buttonFiveiron(View view) {
    }

    public void buttonSixiron(View view) {
    }

    public void buttonSeveniron(View view) {
    }

    public void buttonEightiron(View view) {
    }

    public void buttonNineiron(View view) {
    }

    public void buttonPW(View view) {
    }

    public void buttonSW(View view) {
    }

    public void buttonFiftysix(View view) {
    }

    public void buttonSixty(View view) {
    }
}






package tamu.thecaddyapp;

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

/**
 * Created by Owner on 11/12/2017.
 */

public class DataHandler {
    public static final String _ID = "_ID";
    public static final String TABLE_NAME = "SHOT_AVERAGES";
    public static final String DATA_BASE_NAME = "thecaddyappdb";
    public static final int DATABASE_VERSION = 1;
    public static final String TABLE_CREATE = "CREATE TABLE " + TABLE_NAME + "(" + _ID + "TEXT NOT NULL"+ ") VALUES(150)";


    DataBaseHelper dbhelper;
    Context ctx;
    SQLiteDatabase db;

    public DataHandler(Context ctx) {
        this.ctx = ctx;
        dbhelper = new DataBaseHelper(ctx);
    }

    private static class DataBaseHelper extends SQLiteOpenHelper {
        public DataBaseHelper(Context ctx) {
            super(ctx, DATA_BASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            try {
                db.execSQL(TABLE_CREATE);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int i, int i1) {
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
            onCreate(db);
        }
    }

    public DataHandler open(){
        db = dbhelper.getWritableDatabase();
        return this;
    }

    public void close() {
        dbhelper.close();
    }

    public long insertData(int recalDist){
        ContentValues content = new ContentValues();
        String clubName = "Driver";
        content.put(_ID, clubName);
        content.put(_ID, recalDist);
        return db.insertOrThrow(TABLE_NAME, null, content);
    }

}




另外,我对此工作了一段时间,所以这些文件与我曾经拥有的一些东西有很多不同,实际上只是试验但不完全确定错误,这段代码我要去对于一个包含值的列,稍后在我知道正在创建数据库文件后将实现其他列。

由于

1 个答案:

答案 0 :(得分:0)

关于未在Android监视器中显示的SQl文件,请确保您拥有22或更低版本的设备API。对于22以上的API,它无法正常工作。