2017-01-04 28 views
0

私のアプリケーションは、それだけでこの私に言ってクラッシュaddHistory()方法でSQLiteDatabase db = getWritableDatabase();ラインに達するたび:E/SQLiteLog:(1)getWritableDatabase()でAndroidアプリがクラッシュする。

問題がある可能性がありますか?私はthis.getWriteableDatabase()を使用してみましたが、そのあまりに:(

import android.content.ContentValues; 
import android.content.Context; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 
import android.util.Log; 

public class HistoryDB extends SQLiteOpenHelper { 
    private static final String DATABASE_NAME = "history.db"; 

    private static final String TABLE_HISTORY = "history"; 
    private static final String FIELD_TITLE = "title"; 
    private static final String FIELD_TEMPERATURE = "temperature"; 
    private static final String FIELD_SUMMARY = "summary"; 
    private static final String FIELD_WIND = "wind"; 
    private static final String FIELD_LOCATION_ID = "locationID"; 

    private static final int DATABASE_VERSION = 1; 

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

    @Override 
    public void onCreate(SQLiteDatabase db){ 
     db.execSQL("CREATE TABLE " + TABLE_HISTORY + 
       "(_idHistory INT PRIMARY KEY, " + 
       FIELD_TITLE + " TEXT, " + 
       FIELD_TEMPERATURE + " FLOAT(3,2)), " + 
       FIELD_SUMMARY + " TEXT, " + 
       FIELD_WIND + " TEXT, " + 
       FIELD_LOCATION_ID + " INT(3));"); 
    } 

    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){ 
     //handle database upgrade as needed 
    } 

    public long addHistory(String title, float temp, String sum, String wind, int locationId){ 
     SQLiteDatabase db = getWritableDatabase(); 

     ContentValues values = new ContentValues(); 
     values.put(FIELD_TITLE, title); 
     values.put(FIELD_TEMPERATURE, temp); 
     values.put(FIELD_SUMMARY, sum); 
     values.put(FIELD_WIND, wind); 
     values.put(FIELD_LOCATION_ID, locationId); 
     return db.insert(TABLE_HISTORY, null, values); 
    } 
} 


01-04 16:17:57.643 11289-11289/? I/art: Late-enabling -Xcheck:jni 
01-04 16:17:57.991 11289-11289/com.example.h454951.imtrying W/System: ClassLoader referenced unknown path: /data/app/com.example.h454951.imtrying-1/lib/arm64 
01-04 16:17:57.995 11289-11289/com.example.h454951.imtrying I/InstantRun: Instant Run Runtime started. Android package is com.example.h454951.imtrying, real application class is null. 
01-04 16:17:58.167 11289-11289/com.example.h454951.imtrying W/System: ClassLoader referenced unknown path: /data/app/com.example.h454951.imtrying-1/lib/arm64 
01-04 16:17:58.285 11289-11289/com.example.h454951.imtrying I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl 
01-04 16:17:58.343 11289-11289/com.example.h454951.imtrying W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 
01-04 16:17:58.546 11289-11289/com.example.h454951.imtrying I/HwSecImmHelper: mSecurityInputMethodService is null 
01-04 16:17:58.624 11289-11337/com.example.h454951.imtrying I/OpenGLRenderer: Initialized EGL, version 1.4 
01-04 16:17:58.743 11289-11289/com.example.h454951.imtrying W/IInputConnectionWrapper: getExtractedText on inactive InputConnection 
01-04 16:17:58.743 11289-11289/com.example.h454951.imtrying W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection 
01-04 16:17:58.744 11289-11289/com.example.h454951.imtrying W/IInputConnectionWrapper: getSelectedText on inactive InputConnection 
01-04 16:17:58.744 11289-11289/com.example.h454951.imtrying W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection 
01-04 16:18:04.044 11289-11289/com.example.h454951.imtrying E/SQLiteLog: (1) 
01-04 16:18:04.133 11289-11289/com.example.h454951.imtrying I/Process: Sending signal. PID: 11289 SIG: 9 

クリーン&後のファイル名を指定して実行ログとは運があなたがここに余分な近いかっこに)を持って

01-04 16:41:50.130 19496-19496/? I/art: Late-enabling -Xcheck:jni 
01-04 16:41:50.264 19496-19496/com.example.h454951.imtrying W/System: ClassLoader referenced unknown path: /data/app/com.example.h454951.imtrying-1/lib/arm64 
01-04 16:41:50.269 19496-19496/com.example.h454951.imtrying I/InstantRun: Instant Run Runtime started. Android package is com.example.h454951.imtrying, real application class is null. 
01-04 16:41:50.416 19496-19496/com.example.h454951.imtrying W/System: ClassLoader referenced unknown path: /data/app/com.example.h454951.imtrying-1/lib/arm64 
01-04 16:41:50.562 19496-19496/com.example.h454951.imtrying I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl 
01-04 16:41:50.632 19496-19496/com.example.h454951.imtrying W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 
01-04 16:41:50.867 19496-19496/com.example.h454951.imtrying I/HwSecImmHelper: mSecurityInputMethodService is null 
01-04 16:41:50.967 19496-19533/com.example.h454951.imtrying I/OpenGLRenderer: Initialized EGL, version 1.4 
01-04 16:41:52.738 19496-19502/com.example.h454951.imtrying W/art: Suspending all threads took: 13.619ms 
01-04 16:41:52.917 19496-19496/com.example.h454951.imtrying E/SQLiteLog: (1) 
01-04 16:41:52.947 19496-19496/com.example.h454951.imtrying I/Process: Sending signal. PID: 19496 SIG: 9 
+1

ここで、logcatは? –

+0

"これは私にこのことを伝えてクラッシュします:E/SQLiteLog:(1)" - クラッシュすると、LogCatにJavaスタックトレースがあります。 – CommonsWare

+0

クラッシュログを投稿する – Alok

答えて

0

再構築しません:

FIELD_TEMPERATURE + " FLOAT(3,2)), " + 

は、それを削除します。

sqliteは長さ/精度の修飾子はまったく気にしないので、(3,2))を完全に削除することもできます。

+0

問題はまだありますが、このタイプミスを指摘してくれてありがとう、sqliteは修飾語を気にしません! – Sidelley

+0

クラッシュした場合、質問にテキストとして投稿する必要があるスタックトレースがあります。 http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – laalto

関連する問題