Java 如何在SQLite数据库中存储日期选择器时间?我的车老是撞坏

Java 如何在SQLite数据库中存储日期选择器时间?我的车老是撞坏,java,android,eclipse,sqlite,timepicker,Java,Android,Eclipse,Sqlite,Timepicker,我使用互联网上的各种资源创建了一个简单的记录保存应用程序。我能够成功地存储文本数据-但是,当我尝试合并时间选择器时,我最终导致整个应用程序崩溃。我在上一篇文章中被指示如何添加此功能,但当我尝试为计时器数据添加字段时,整个应用程序将关闭(当然不会保存数据) (上述用户)指示我使用以下内容: CREATE TABLE ...... dtField date, tmpName Text..... 使用以下命令将日期保存为文本 //样本日期格式-2013-03-21 13:12:00 android

我使用互联网上的各种资源创建了一个简单的记录保存应用程序。我能够成功地存储文本数据-但是,当我尝试合并
时间选择器时,我最终导致整个应用程序崩溃。我在上一篇文章中被指示如何添加此功能,但当我尝试为计时器数据添加字段时,整个应用程序将关闭(当然不会保存数据)

(上述用户)指示我使用以下内容:

CREATE TABLE ...... dtField date, tmpName Text.....
使用以下命令将日期保存为文本

//样本日期格式-2013-03-21 13:12:00

android.text.format.DateFormat.format("yyyy-MM-dd hh:mm:ss", dtDate.getTime())
前半部分我已经实现了(我相信)。下半部分我不太确定如何正确实施(我需要帮助的第一件事),我的应用程序在做出这些更改后也会强制关闭(我需要帮助的第二件事)

非常感谢您对解决此问题的任何帮助!(我有点傻,所以说明越详细越好!)

提前感谢,

阿曼尼·斯旺

附言

我用Robby Pond的建议更新了下面的源代码:

替换

EditText timeEt
编辑文本时间 与

计时器选择器计时器

但是我仍然无法运行下面显示的代码

有人可以看一下日志或问题日志,让我知道您是否可以告诉我是什么导致了这个问题?Robby Pond的建议很有帮助,但我对下面(当前)的源代码有一个更深层次的问题

附言

我知道该错误无法解析为类型通常表示缺少类或可能存在XML问题,但该错误表示“TimePicker无法解析为类型”,但我没有TimePicker.Java-我只想使用下面XML中编码的TimePicker按钮

XML:数据输入

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" android:layout_weight="1">

<LinearLayout android:id="@+id/linearLayout"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical" 
  android:padding="5dp">

  <EditText android:id="@+id/nameEdit"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content" 
     android:imeOptions="actionNext" 
     android:hint="@string/name_hint"
     android:inputType="textPersonName|textCapWords"/>

  <EditText android:id="@+id/capEdit"
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:imeOptions="actionNext" 
     android:hint="@string/cap_hint"
     android:inputType="textPersonName|textCapWords"/>

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Data Limit"
    android:textColor="#ffffff"
    android:textAppearance="?android:textAppearanceMedium" />

<SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:gravity="left"
        android:textColor="#ffffff"
        android:text="10MB" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:gravity="right"
        android:textColor="#ffffff"
        android:text="Unlimited Data" />
</LinearLayout>

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Bandwidth Limit"
    android:textColor="#ffffff"
    android:textAppearance="?android:textAppearanceMedium" />

<SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:gravity="left"
        android:textColor="#ffffff"
        android:text="10kbs" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:textColor="#ffffff"
        android:gravity="right"
        android:text="Unlimited Bandwidth" />
</LinearLayout>

 <TextView
    android:id="@+id/TextView02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:textAppearanceSmall" />

 <TextView
    android:id="@+id/TextView02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="WiFi Time Limit"
    android:textColor="#ffffff"
    android:textAppearance="?android:textAppearanceMedium" />

 <TimePicker
    android:id="@+id/timeEdit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:layout_weight="1.0" />

<EditText
    android:id="@+id/codeEdit"
    android:inputType="textUri"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:lines="1"
    android:hint="@string/code_hint"
    android:imeOptions="actionNext" />




  <Button android:id="@+id/saveBtn" 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_marginTop="15dp"
     android:layout_gravity="center_horizontal"
     android:text="@string/save_btn"/>
 </LinearLayout>
 </ScrollView>
数据库助手JAVA:

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

public class DatabaseOpenHelper extends SQLiteOpenHelper {

public DatabaseOpenHelper(Context context, String name,
        CursorFactory factory, int version) {
    super(context, name, factory, version);
}

@Override
public void onCreate(SQLiteDatabase db) {
    String createQuery = "CREATE TABLE country (_id integer primary key autoincrement,name, cap, code, time);";                 
    db.execSQL(createQuery);        
}

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

}

}
LOGCAT数据:

03-21 17:17:24.276: I/Adreno200-EGLSUB(8655): <ConfigWindowMatch:2165>: Format RGBA_8888.
03-21 17:17:24.276: D/memalloc(8655): ion: Mapped buffer base:0x5ca41000 size:614400 offset:0 fd:57
03-21 17:17:24.276: E/(8655): Can't open file for reading
03-21 17:17:24.276: E/(8655): Can't open file for reading
03-21 17:17:24.376: D/memalloc(8655): ion: Mapped buffer base:0x5d12e000 size:614400 offset:0 fd:61
03-21 17:17:26.188: D/Activity(8655): Activity.onPause(), editTextTapSensorList size: 0
03-21 17:17:26.268: I/Adreno200-EGLSUB(8655): <ConfigWindowMatch:2165>: Format  RGBA_8888.
03-21 17:17:26.278: D/memalloc(8655): ion: Mapped buffer base:0x5d4ce000 size:614400  offset:0 fd:68
03-21 17:17:26.318: D/memalloc(8655): ion: Mapped buffer base:0x5d937000 size:614400 offset:0 fd:72
03-21 17:17:26.328: D/memalloc(8655): ion: Unmapping buffer  base:0x5ca41000 size:614400
03-21 17:17:26.328: D/memalloc(8655): ion: Unmapping buffer  base:0x5d12e000 size:614400
03-21 17:17:26.468: D/Activity(8655): Activity.onPause(), editTextTapSensorList size: 0
03-21 17:17:26.549: D/memalloc(8655): ion: Mapped buffer base:0x5c929000 size:614400 offset:0 fd:54
03-21 17:17:26.619: W/IInputConnectionWrapper(8655): getExtractedText on inactive  InputConnection
03-21 17:17:26.639: W/IInputConnectionWrapper(8655): getExtractedText on inactive InputConnection
03-21 17:17:48.322: D/Activity(8655): Activity.onPause(), editTextTapSensorList size: 0
03-21 17:17:48.342: W/dalvikvm(8655): threadid=1: thread exiting with uncaught exception (group=0x410889d8)
03-21 17:17:48.352: E/AndroidRuntime(8655): FATAL EXCEPTION: main
03-21 17:17:48.352: E/AndroidRuntime(8655): java.lang.Error: Unresolved compilation  problems: 
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a type
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a type
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a type
03-21 17:17:48.352: E/AndroidRuntime(8655):     timeEdit cannot be resolved or is not a field
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a  type
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a  type
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a  type
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  com.nfc.linkingmanager.AddEditCountry.<init>(AddEditCountry.java:19)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at java.lang.Class.newInstanceImpl(Native Method)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  java.lang.Class.newInstance(Class.java:1319)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  android.app.Instrumentation.newActivity(Instrumentation.java:1025)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1875)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.os.Looper.loop(Looper.java:137)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.app.ActivityThread.main(ActivityThread.java:4477)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  java.lang.reflect.Method.invokeNative(Native Method)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at java.lang.reflect.Method.invoke(Method.java:511)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at   com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  dalvik.system.NativeStart.main(Native Method)

timeEt字段应该是时间选择器。您之所以得到ClassCastException,是因为在活动中您将其声明为EditText

替换

EditText timeEt


我已经用你的建议更新了上面的源代码以及我的源代码,但仍然失败。我认为这主要是因为时间选择器无法解决我在“问题”日志中看到的类型错误。有人对此有任何建议吗?添加时间选择器导入。Eclipse中的Ctrl-Shift-O。
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseOpenHelper extends SQLiteOpenHelper {

public DatabaseOpenHelper(Context context, String name,
        CursorFactory factory, int version) {
    super(context, name, factory, version);
}

@Override
public void onCreate(SQLiteDatabase db) {
    String createQuery = "CREATE TABLE country (_id integer primary key autoincrement,name, cap, code, time);";                 
    db.execSQL(createQuery);        
}

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

}

}
03-21 17:17:24.276: I/Adreno200-EGLSUB(8655): <ConfigWindowMatch:2165>: Format RGBA_8888.
03-21 17:17:24.276: D/memalloc(8655): ion: Mapped buffer base:0x5ca41000 size:614400 offset:0 fd:57
03-21 17:17:24.276: E/(8655): Can't open file for reading
03-21 17:17:24.276: E/(8655): Can't open file for reading
03-21 17:17:24.376: D/memalloc(8655): ion: Mapped buffer base:0x5d12e000 size:614400 offset:0 fd:61
03-21 17:17:26.188: D/Activity(8655): Activity.onPause(), editTextTapSensorList size: 0
03-21 17:17:26.268: I/Adreno200-EGLSUB(8655): <ConfigWindowMatch:2165>: Format  RGBA_8888.
03-21 17:17:26.278: D/memalloc(8655): ion: Mapped buffer base:0x5d4ce000 size:614400  offset:0 fd:68
03-21 17:17:26.318: D/memalloc(8655): ion: Mapped buffer base:0x5d937000 size:614400 offset:0 fd:72
03-21 17:17:26.328: D/memalloc(8655): ion: Unmapping buffer  base:0x5ca41000 size:614400
03-21 17:17:26.328: D/memalloc(8655): ion: Unmapping buffer  base:0x5d12e000 size:614400
03-21 17:17:26.468: D/Activity(8655): Activity.onPause(), editTextTapSensorList size: 0
03-21 17:17:26.549: D/memalloc(8655): ion: Mapped buffer base:0x5c929000 size:614400 offset:0 fd:54
03-21 17:17:26.619: W/IInputConnectionWrapper(8655): getExtractedText on inactive  InputConnection
03-21 17:17:26.639: W/IInputConnectionWrapper(8655): getExtractedText on inactive InputConnection
03-21 17:17:48.322: D/Activity(8655): Activity.onPause(), editTextTapSensorList size: 0
03-21 17:17:48.342: W/dalvikvm(8655): threadid=1: thread exiting with uncaught exception (group=0x410889d8)
03-21 17:17:48.352: E/AndroidRuntime(8655): FATAL EXCEPTION: main
03-21 17:17:48.352: E/AndroidRuntime(8655): java.lang.Error: Unresolved compilation  problems: 
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a type
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a type
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a type
03-21 17:17:48.352: E/AndroidRuntime(8655):     timeEdit cannot be resolved or is not a field
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a  type
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a  type
03-21 17:17:48.352: E/AndroidRuntime(8655):     TimePicker cannot be resolved to a  type
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  com.nfc.linkingmanager.AddEditCountry.<init>(AddEditCountry.java:19)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at java.lang.Class.newInstanceImpl(Native Method)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  java.lang.Class.newInstance(Class.java:1319)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  android.app.Instrumentation.newActivity(Instrumentation.java:1025)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1875)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.os.Looper.loop(Looper.java:137)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at android.app.ActivityThread.main(ActivityThread.java:4477)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  java.lang.reflect.Method.invokeNative(Native Method)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at java.lang.reflect.Method.invoke(Method.java:511)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at   com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
03-21 17:17:48.352: E/AndroidRuntime(8655):     at  dalvik.system.NativeStart.main(Native Method)
    Description Resource    Path    Location    Type
user3SettingsSave cannot be resolved or is not a field  User3Settings.java  /NFC Linking Manager/src/com/nfc/linkingmanager line 35 Java Problem
The import android.content.Context is never used    AppActivity.java    /NFC Linking Manager/src/com/nfc/linkingmanager line 5  Java Problem
The import android.view.View.OnClickListener is never used  AppActivity.java    /NFC Linking Manager/src/com/nfc/linkingmanager line 13 Java Problem
The value of the field AppActivity.button1 is not used  AppActivity.java    /NFC Linking Manager/src/com/nfc/linkingmanager line 18 Java Problem
The value of the field AppActivity.button2 is not used  AppActivity.java    /NFC Linking Manager/src/com/nfc/linkingmanager line 18 Java Problem
user3Tap cannot be resolved to a type   User3Settings.java  /NFC Linking Manager/src/com/nfc/linkingmanager line 40 Java Problem
The value of the field AppActivity.button3 is not used  AppActivity.java    /NFC Linking Manager/src/com/nfc/linkingmanager line 18 Java Problem
TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 19 Java Problem
TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 30 Java Problem
TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 30 Java Problem
The method deactivate() from the type Cursor is deprecated  CountryList.java    /NFC Linking Manager/src/com/nfc/linkingmanager line 52 Java Problem
The constructor SimpleCursorAdapter(Context, int, Cursor, String[], int[]) is deprecated    CountryList.java    /NFC Linking Manager/src/com/nfc/linkingmanager line 33 Java Problem
The import android.app.AlertDialog is never used    User1.java  /NFC Linking Manager/src/com/nfc/linkingmanager line 4  Java Problem
The import android.view.View.OnClickListener is never used  User1.java  /NFC Linking Manager/src/com/nfc/linkingmanager line 12 Java Problem
The method deactivate() from the type Cursor is deprecated  NewCore.java    /NFC Linking Manager/src/com/nfc/linkingmanager line 54 Java Problem
The constructor SimpleCursorAdapter(Context, int, Cursor, String[], int[]) is deprecated    NewCore.java    /NFC Linking Manager/src/com/nfc/linkingmanager line 35 Java Problem
The import android.content.DialogInterface is never used    User1.java  /NFC Linking Manager/src/com/nfc/linkingmanager line 6  Java Problem
The import android.widget.Button is never used  Link.java   /NFC Linking Manager/src/com/nfc/linkingmanager line 5  Java Problem
The import android.content.Intent is never used Link.java   /NFC Linking Manager/src/com/nfc/linkingmanager line 6  Java Problem
The import android.view.View.OnClickListener is never used  User1Settings.java  /NFC Linking Manager/src/com/nfc/linkingmanager line 10 Java Problem
The import android.view.View is never used  Link.java   /NFC Linking Manager/src/com/nfc/linkingmanager line 7  Java Problem
The import android.view.View.OnClickListener is never used  Link.java   /NFC Linking Manager/src/com/nfc/linkingmanager line 8  Java Problem
TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 99 Java Problem
TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 91 Java Problem
TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 41 Java Problem
timeEdit cannot be resolved or is not a field   AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 30 Java Problem
The method showDialog(int) from the type Activity is deprecated User2Settings.java   /NFC Linking Manager/src/com/nfc/linkingmanager    line 37 Java Problem
EditText timeEt
TimePicker timeEt