今回、初めてAndroidアプリの開発をしています。
IDEはAndroid Studio、言語はKotlinを使用しております。
ORMライブラリExposedを使用して、PostgreSQLに接続したいのですが、トランザクションの開始時に「java.lang.NoClassDefFoundError」が発生します。
以下にLogcatの内容を記載します。
Logcat
2022-04-27 09:01:59.516 6816-6850/test.com E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1 Process: test.com, PID: 6816 java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/ManagementFactory; at org.postgresql.util.PGPropertyMaxResultBufferParser.adjustResultSize(PGPropertyMaxResultBufferParser.java:195) at org.postgresql.util.PGPropertyMaxResultBufferParser.parseProperty(PGPropertyMaxResultBufferParser.java:42) at org.postgresql.core.PGStream.setMaxResultBuffer(PGStream.java:760) at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:118) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:235) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223) at org.postgresql.Driver.makeConnection(Driver.java:402) at org.postgresql.Driver.connect(Driver.java:261) at java.sql.DriverManager.getConnection(DriverManager.java:580) at java.sql.DriverManager.getConnection(DriverManager.java:218) at org.jetbrains.exposed.sql.Database$Companion$connect$10.invoke(Database.kt:206) at org.jetbrains.exposed.sql.Database$Companion$connect$10.invoke(Database.kt:206) at org.jetbrains.exposed.sql.Database$Companion$doConnect$3.invoke(Database.kt:127) at org.jetbrains.exposed.sql.Database$Companion$doConnect$3.invoke(Database.kt:128) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction$connectionLazy$1.invoke(ThreadLocalTransactionManager.kt:69) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction$connectionLazy$1.invoke(ThreadLocalTransactionManager.kt:68) at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction.getConnection(ThreadLocalTransactionManager.kt:75) at org.jetbrains.exposed.sql.Transaction.getConnection(Unknown Source:2) at org.jetbrains.exposed.sql.vendors.VendorDialect.tableExists(Default.kt:688) at org.jetbrains.exposed.sql.QueriesKt.exists(Queries.kt:236) at org.jetbrains.exposed.sql.SchemaUtils.createStatements(SchemaUtils.kt:96) at org.jetbrains.exposed.sql.SchemaUtils.create(SchemaUtils.kt:258) at org.jetbrains.exposed.sql.SchemaUtils.create$default(SchemaUtils.kt:256) at test.com.MainActivity$createTables$1$job$1$1.invoke(MainActivity.kt:108) at test.com.MainActivity$createTables$1$job$1$1.invoke(MainActivity.kt:105) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction$run(ThreadLocalTransactionManager.kt:189) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.access$inTopLevelTransaction$run(ThreadLocalTransactionManager.kt:1) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$inTopLevelTransaction$1.invoke(ThreadLocalTransactionManager.kt:215) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:223) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:214) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$transaction$1.invoke(ThreadLocalTransactionManager.kt:165) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:223) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:135) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:132) at test.com.MainActivity$createTables$1$job$1.invokeSuspend(MainActivity.kt:105) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) 2022-04-27 09:01:59.531 6816-6850/test.com E/AndroidRuntime: at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664) Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@da641f4, Dispatchers.Default] Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.management.ManagementFactory" on path: DexPathList[[zip file "/data/app/~~YQyj_zOvonhzIrbGOCs5_g==/test.com-O_t3n2ZKM-K0gH9au0lKTA==/base.apk"],nativeLibraryDirectories=[/data/app/~~YQyj_zOvonhzIrbGOCs5_g==/test.com-O_t3n2ZKM-K0gH9au0lKTA==/lib/x86, /system/lib, /system_ext/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 43 more
「java.lang.management.ManagementFactory」が見つからないようなのですが、調べてみても解決方法がわかりませんでした。
ソースコードは以下になります。
build.gradle
plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'kotlin-android-extensions' } android { compileSdk 31 defaultConfig { applicationId "test.com" minSdk 21 targetSdk 32 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } } dependencies { def exposed_version = '0.38.2' implementation "org.jetbrains.exposed:exposed-core:$exposed_version" implementation "org.jetbrains.exposed:exposed-dao:$exposed_version" implementation "org.jetbrains.exposed:exposed-jdbc:$exposed_version" implementation "org.jetbrains.exposed:exposed-java-time:$exposed_version" def postgresql_version = '42.3.4' implementation "org.postgresql:postgresql:${postgresql_version}" implementation 'com.journeyapps:zxing-android-embedded:4.3.0' implementation 'com.google.zxing:core:3.4.1' implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.3' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' }
MainActibity.ky
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) btn_comit.setOnClickListener { createTables() } } fun createTables() = runBlocking() { val job = GlobalScope.launch { var db = Database.connect("jdbc:postgresql://192.168.0.32:5432/test", driver = "org.postgresql.Driver", user = "postgres", password = "password") transaction(db) { addLogger(StdOutSqlLogger) SchemaUtils.create (testTable) } } job.join() } }
環境
Android Studioバージョン: Bumblebee | 2021.1.1 Patch 3 Build #AI-211.7628.21.2111.8309675, built on March 17, 2022 ランタイムバージョン: 11.0.11+9-b60-7590822 amd64 Kotlinプラグインバージョン:211-1.6.21-release-334-AS7442.40 PostgreSQLバージョン:14.2
このエラーの解決方法をご教授いただけないでしょうか。
よろしくお願いいたします。
あなたの回答
tips
プレビュー