Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 近;空";:语法错误(代码1):,编译时:插入到_Android - Fatal编程技术网

Android 近;空";:语法错误(代码1):,编译时:插入到

Android 近;空";:语法错误(代码1):,编译时:插入到,android,Android,我正在学习如何在SQLite数据库中创建和插入值。该应用程序有一个按钮和计时器。单击该按钮可启动计时器,再次单击可停止计时器。停止时,值将存储到数据库中。我可以从androidstudio中的文件资源管理器中看到,正在创建数据库和表。日志中有证据表明启动和停止时间也被捕获,但这些值没有被插入数据库。我正在粘贴用于创建数据库然后插入记录的代码片段。我还将复制输出错误的日志片段。请帮忙 import android.content.ContentValues; import android.d

我正在学习如何在SQLite数据库中创建和插入值。该应用程序有一个按钮和计时器。单击该按钮可启动计时器,再次单击可停止计时器。停止时,值将存储到数据库中。我可以从androidstudio中的文件资源管理器中看到,正在创建数据库和表。日志中有证据表明启动和停止时间也被捕获,但这些值没有被插入数据库。我正在粘贴用于创建数据库然后插入记录的代码片段。我还将复制输出错误的日志片段。请帮忙

   import android.content.ContentValues; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.content.Context; import android.util.Log; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class DBHelper extends SQLiteOpenHelper {

        public static final int DATABASE_VERSION = 1;
        public static final String DATABASE_NAME = "Feeds.db";
        public static String TIMESTAMP_START;
        public static String   TIMESTAMP_END;
        public static int _ID = 0;
        public static final String DATABASE_TABLE = "T_FEEDRECORDS";
        private static final String SQL_CREATE_ENTRIES = "CREATE TABLE T_FEEDRECORDS ( _ID  INTEGER primary key autoincrement,  TIMESTAMP_START TEXT, TIMESTAMP_END TEXT)" ;

        public DBHelper(Context context)
        {
            super(context,DATABASE_NAME, null, DATABASE_VERSION );
        }


        public void onCreate(SQLiteDatabase db)
        {
            Log.d("onCreate", "before DB Create");
            try {
                db.execSQL(SQL_CREATE_ENTRIES);
            } catch(SQLException ex){ Log.d("onCreate", "DB creation exception:"+ ex.getMessage()); }
            Log.d("onCreate", "after DB Create" + db.toString());
        }

        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
        {

            db.execSQL("DROP TABLE IF IT EXISTS " + DATABASE_TABLE);
            Log.d("onUpgrade", "dropping table");
             onCreate(db);
        }

        public void createFeedRecord (FeedRecords feedRecord){
            ContentValues feedContent = new ContentValues();
            feedContent.put(TIMESTAMP_START,  feedRecord.getStartTime());
            feedContent.put(TIMESTAMP_END,  feedRecord.getEndTime());
            try {
                SQLiteDatabase db = this.getWritableDatabase();
                Log.d("createFeedRecord values before insert", "start time : " + feedRecord.getStartTime() + " Timer end:" + feedRecord.getEndTime());
                db.insertOrThrow(DATABASE_TABLE,null, feedContent );
                db.close();
            } catch(SQLException ex) {Log.d("SQL Exdception in create feed record", "" + ex.getLocalizedMessage());}
            Log.d("createFeedRecord", "after content values");
        } 
}
日志片段

02-04 09:57:43.287    2213-2213/? D/onClick......﹕ Timer Start time: 150204_095743
....
02-04 10:01:25.738    2213-2213/? D/onClick......﹕ Timer Stop time: 150204_100125
02-04 10:01:25.738    2213-2213/? D/inster Time Record﹕ after create Feed
02-04 10:01:25.754    1239-1293/? W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client

02-04 10:01:25.763    2213-2213/? D/createFeedRecord values before insert﹕ start time : 150204_095743 Timer end:150204_100125
02-04 10:01:25.763    2213-2213/? E/SQLiteLog﹕ (1) near "null": syntax error
02-04 10:01:25.763    2213-2213/? D/SQL Exdception in create feed record﹕ near "null": syntax error (code 1): , while compiling: INSERT INTO T_FEEDRECORDS(null) VALUES (?)
02-04 10:01:25.763    2213-2213/? D/createFeedRecord﹕ after content values
您需要分配

  public static String TIMESTAMP_START="TIMESTAMP_START";
  public static String TIMESTAMP_END="TIMESTAMP_END";
直接提供列名

  ContentValues feedContent = new ContentValues();
  feedContent.put("TIMESTAMP_START",  feedRecord.getStartTime());
  feedContent.put("TIMESTAMP_END",  feedRecord.getEndTime());

呸!!!!当然可以!!!删除了变量并直接提供了列名,这一切都起了作用。非常感谢您的快速回复!!!很抱歉只是学习如何使用这个网站上的工具。。。我现在已经接受了!!!