我一直在尝试在我的项目中使用房间数据库,但到目前为止它一直在崩溃,我无法确定原因是什么......
以下是我的案例:
当用户在对话框中取一个logpoint并按下ok时,会调用此函数
fun manualOkClicked() {
/*Check if all fields are valid ( if they are, location is created and folderId is saved )*/
if (logpoint.canCreateLocation(context) && logpoint.canSelectFolder(view?.getSelectedFolder())) {
DataSource.saveLogpoint(logpoint)
}
}
以下是我保存日志点的方法:
fun saveLogpoint(logpoint: UserLogpoint) {
Thread({
mydb.logpointDao().insert(logpoint)
}).start()
}
我的应用程序崩溃了这个日志:
12-27 16:17:31.108 17932-17941/com.example.myproject.debug A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x61724474 in tid 17941 (FinalizerDaemon)
[ 12-27 16:17:31.109 2247: 2247 W/ ]
debuggerd: handling request: pid=17932 uid=10145 gid=10145 tid=17941
12-27 16:17:31.120 2379-2379/? E/audit: type=1400 audit(1514387851.111:150): avc: denied { search } for pid=19174 comm="debuggerd" name="com.google.android.gms" dev="dm-1" ino=65716 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SECMOBILE_7.0_0005 audit_filtered
12-27 16:17:31.131 2379-2379/? E/audit: type=1400 audit(1514387851.121:151): avc: denied { search } for pid=19174 comm="debuggerd" name="com.google.android.gms" dev="dm-1" ino=65716 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SECMOBILE_7.0_0005 audit_filtered
12-27 16:17:31.131 2379-2379/? E/audit: type=1400 audit(1514387851.121:152): avc: denied { search } for pid=19174 comm="debuggerd" name="com.google.android.gms" dev="dm-1" ino=65716 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SECMOBILE_7.0_0005 audit_filtered
12-27 16:17:31.209 19174-19174/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
12-27 16:17:31.210 19174-19174/? A/DEBUG: Build fingerprint: 'samsung/xcover4ltexx/xcover4lte:7.0/NRD90M/G390FXXU1AQC1:user/release-keys'
12-27 16:17:31.210 19174-19174/? A/DEBUG: Revision: '4'
12-27 16:17:31.210 19174-19174/? A/DEBUG: ABI: 'arm'
12-27 16:17:31.210 19174-19174/? A/DEBUG: pid: 17932, tid: 17941, name: FinalizerDaemon >>> com.example.myproject.debug <<<
12-27 16:17:31.210 19174-19174/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x61724474
12-27 16:17:31.210 19174-19174/? A/DEBUG: r0 cb61ad58 r1 00000000 r2 3f800000 r3 00000012
12-27 16:17:31.210 19174-19174/? A/DEBUG: r4 cb61ad58 r5 1335b498 r6 6fd77fc8 r7 6f96bff4
12-27 16:17:31.210 19174-19174/? A/DEBUG: r8 1335b4c0 r9 de870900 sl cb61ad58 fp ffffffff
12-27 16:17:31.210 19174-19174/? A/DEBUG: ip 61724474 sp e7424420 lr e9cc3c1b pc 61724474 cpsr 200f0010
12-27 16:17:31.879 19174-19174/? A/DEBUG: backtrace:
12-27 16:17:31.879 19174-19174/? A/DEBUG: #00 pc 61724474 <unknown>
12-27 16:17:31.880 19174-19174/? A/DEBUG: #01 pc 00041c19 /system/lib/libbinder.so (_ZN7android6Parcel14freeDataNoInitEv+32)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #02 pc 00041bf1 /system/lib/libbinder.so (_ZN7android6ParcelD1Ev+4)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #03 pc 00097249 /system/lib/libandroid_runtime.so
12-27 16:17:31.880 19174-19174/? A/DEBUG: #04 pc 025b981d /system/framework/arm/boot-framework.oat (offset 0x1ea5000) (android.os.Parcel.nativeDestroy+80)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #05 pc 025b9077 /system/framework/arm/boot-framework.oat (offset 0x1ea5000) (android.os.Parcel.destroy+74)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #06 pc 025bc297 /system/framework/arm/boot-framework.oat (offset 0x1ea5000) (android.os.Parcel.finalize+42)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #07 pc 005e12b3 /system/framework/arm/boot-core-libart.oat (offset 0x47e000) (java.lang.Daemons$FinalizerDaemon.doFinalize+110)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #08 pc 005e14c1 /system/framework/arm/boot-core-libart.oat (offset 0x47e000) (java.lang.Daemons$FinalizerDaemon.run+380)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #09 pc 005f86ad /system/framework/arm/boot.oat (offset 0x56f000) (java.lang.Thread.run+48)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #10 pc 000a9241 /system/lib/libart.so (art_quick_invoke_stub_internal+64)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #11 pc 00406e69 /system/lib/libart.so (art_quick_invoke_stub+232)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #12 pc 000b0535 /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+140)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #13 pc 0031636b /system/lib/libart.so (_ZN3artL18InvokeWithArgArrayERKNS_33ScopedObjectAccessAlreadyRunnableEPNS_9ArtMethodEPNS_8ArgArrayEPNS_6JValueEPKc+58)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #14 pc 00317119 /system/lib/libart.so (_ZN3art35InvokeVirtualOrInterfaceWithJValuesERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_jmethodIDP6jvalue+256)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #15 pc 0032e319 /system/lib/libart.so (_ZN3art6Thread14CreateCallbackEPv+848)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #16 pc 00047f83 /system/lib/libc.so (_ZL15__pthread_startPv+22)
12-27 16:17:31.880 19174-19174/? A/DEBUG: #17 pc 0001a151 /system/lib/libc.so (__start_thread+6)
有没有人知道这里发生了什么以及为什么会崩溃?
DataSource是一个Object类,它是Kotlin中的Singleton。它初始化如下:
public class MyApp extends MultiDexApplication {
@Override
public void onCreate() {
//Initialize database
DataSource.INSTANCE.setMyBd(
Room.databaseBuilder(getApplicationContext(),
MyDb.class, "my-db").build());
}}
插入和删除只是来自房间的注释:
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(logpoint: UserLogpoint)
@Delete
fun delete(logpoint: UserLogpoint)
答案 0 :(得分:0)
很抱歉你的时间在你们这里。正如您可能已经猜到的那样,问题在于其他问题。
问题在于对象的类本身。因为房间无法解析他不知道的对象,所以他无法解析它们。因此,我放置了一个像这样的转换:
@TypeConverter
fun cast2(location: String) = Utils.General.deserializeFromJson(location,Location::class.java)
@TypeConverter
fun cast1(location: Location) = Utils.General.serializeToJson(location)
但这不起作用,因为我无法以这种方式序列化某个位置,而我得到的错误就是您在上面看到的错误。