我一直得到这个“表没有列名称”的错误,我在这里看到了一些解决方案,但没有一个对我有帮助。我确实看到我应该去设置/应用程序并清除数据,但我无法在设置中找到它,所以我希望我能在这里找到答案。
package com.bengu.bvb;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import static com.bengu.bvb.TableData.*;
public class DataBaseOperation extends SQLiteOpenHelper {
public static final int database_version=1;
public String CREATE_QUERY="CREATE TABLE "+ TableInfo.TABLE_NAME+"("+TableInfo.PLAYER_NAME+" TEXT,"+ TableInfo.PLAYER_Family+" TEXT);";
public DataBaseOperation(Context context) {
super(context, TableInfo.DATABASE_NAME, null, database_version);
Log.d("Database operations","Database created");
}
@Override
public void onCreate(SQLiteDatabase sdb) {
sdb.execSQL(CREATE_QUERY);
Log.d("Database operations", "Table created");
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
}
public void putInformation(DataBaseOperation dop,String name,String family)
{
SQLiteDatabase SQ =dop.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(TableInfo.PLAYER_Family, family);
long k= SQ.insert(TableInfo.TABLE_NAME, null,cv);
Log.d("Database operations", "One raw inserted");
}
package com.bengu.bvb;
public class TableData {
public TableData()
{
}
public static abstract class TableInfo implements BaseColumns
{
public static final String PLAYER_NAME="player_name";
public static final String PLAYER_Family="last_name";
public static final String DATABASE_NAME="player_info";
public static final String TABLE_NAME="reg_info";
}
现在我没有得到这个错误我得到另一个错误。
java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:14673)
at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2473)
at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:688)
at android.content.ContentProvider$Transport.call(ContentProvider.java:325)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:275)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main2Activity"
android:label="@string/title_activity_main2" >
</activity>
<activity
android:name=".Menu"
android:label="@string/title_activity_menu" >
</activity>
<activity
android:name=".MainApp"
android:label="@string/title_activity_main_app" >
</activity>
<activity
android:name=".AddScreen"
android:label="@string/title_activity_add_screen" >
</activity>
</application>
答案 0 :(得分:0)
您缺少_id
列。
变化
"CREATE TABLE "+ TableInfo.TABLE_NAME+"("+TableInfo.PLAYER_NAME+" TEXT,"+ TableInfo.PLAYER_Family+" TEXT);";
到
"CREATE TABLE "+ TableInfo.TABLE_NAME+"(_id INTEGER PRIMARY KEY AUTOINCREMENT, "+TableInfo.PLAYER_NAME+" TEXT,"+ TableInfo.PLAYER_Family+" TEXT);";