gpt4 book ai didi

javascript - Android SQL 数据库文件未出现

转载 作者:行者123 更新时间:2023-11-29 02:35:41 25 4
gpt4 key购买 nike

我正在开发一个类(class)应用程序,它将使用 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);
}

}

此外,我在这方面工作了一段时间,所以这些文件与我拥有的一些东西有很大不同,真的只是试验但不完全确定哪里出了问题,这段代码我正在为一个列设置值和在我知道正在创建数据库文件后,稍后将实现附加列。

谢谢

最佳答案

关于SQl 文件在Android 监视器中不显示,请确保您的设备API 22 或以下。它不适用于 22 以上的 API。

关于javascript - Android SQL 数据库文件未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47257997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com