Kotlin java.lang.AssertionError: numMsgsRcvd:1 должно быть меньше numMsgsSent:1Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Kotlin java.lang.AssertionError: numMsgsRcvd:1 должно быть меньше numMsgsSent:1

Сообщение Anonymous »

Я получаю ошибку SQL, когда пытаюсь проверить, существует ли таблица, с которой я собираюсь работать, или нет. Я работаю с MSSQL и только учусь устанавливать это соединение. При первом запуске я получаю сообщение об успешном подключении к базе данных. Но когда я пытаюсь выполнить эту проверку или что-то еще, я получаю следующую ошибку.
Мои зависимости и версии:

Код: Выделить всё

[versions]
agp = "8.6.1"
androidxMaterialIconsExtended = "1.7.2"
hiltAndroid = "2.52"
hiltLifecycleViewmodel = "1.2.0"
kotlin = "2.0.20"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
kotlinxCoroutinesAndroid = "1.8.1"
kotlinxCoroutinesCore = "1.8.1"
lifecycleRuntimeKtx = "2.8.6"
activityCompose = "1.9.2"
composeBom = "2024.09.02"
journeyappsZxingAndroidEmbeddedVersion = "4.3.0"
navigationCompose = "2.8.1"
kspVersion = "2.0.20-1.0.24"
mssqlJdbc = "12.8.0.jre11"
exposed = "0.54.0"
roomKtx = "2.6.1"
roomRuntime = "2.6.1"
roomRxjava2 = "2.6.1"
slf4jSimple = "1.7.30"

Код: Выделить всё

class DBRepository @Inject constructor() {

private val url =
"jdbc:sqlserver://[IP Address];databaseName=dbName;user=user3;password=password2;encrypt=false;trustServerCertificate=true"

init {
try {
connectToDatabase()
} catch (e: Exception) {
Log.e("DBRepository", "Initialization failed: ${e.message}")
}
}

private fun connectToDatabase() {
try {
Database.connect(url = url, driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver")
Log.d("DBRepository", "Database connection successful.")
println("Database connection successful.")
} catch (e: Exception) {
println("Database connection failed: ${e.message}")
println("Database connection failed: $e")
Log.e("DBRepository", "Database connection failed: ${e.message}")
}
}

suspend fun ensureTableExists() {
withContext(Dispatchers.IO) {
try {
transaction {
val tableExists = exec(buildString {
append("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Barcode'")
}) { resultSet ->
resultSet.next()
}
if (tableExists != true) {
exec(buildString {
append("CREATE TABLE dbo.Barcode (id INT PRIMARY KEY IDENTITY(1,1), barkodAd NVARCHAR(255), barkodYol NVARCHAR(255), parametreRef INT, durum BIT)")
})
println("Table 'Barcode' created successfully.")
} else {
println("Table 'Barcode' already exists.")
}
}
} catch (e: Exception) {
println("Error occurred while ensuring table existence: ${e.message}")
println("Error occurred while ensuring table existence: $e")
e.printStackTrace()
}
}
}
}

Код: Выделить всё

@HiltViewModel
class DBViewModel @Inject constructor(private val repository: DBRepository) : ViewModel() {

fun checkIfTableExists() {
viewModelScope.launch(Dispatchers.IO) {
try {
repository.ensureTableExists()
println("Table check and creation (if necessary) complete.")
} catch (e: Exception) {
println("Error: ${e.message}")
e.printStackTrace()
}
}
}
}

Код: Выделить всё

FATAL EXCEPTION: DefaultDispatcher-worker-1
Process: com.example.barcodescanningm3, PID: 5146
java.lang.AssertionError:  n u m M s g s R c v d : 1   s h o u l d   b e   l e s s   t h a n   n u m M s g s S e n t : 1 < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . T D S R e a d e r . r e a d P a c k e t ( I O B u f f e r . j a v a : 6 8 8 0 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . T D S R e a d e r . n e x t P a c k e t ( I O B u f f e r . j a v a : 6 8 4 4 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . T D S R e a d e r . e n s u r e P a y l o a d ( I O B u f f e r . j a v a : 6 8 1 6 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . T D S R e a d e r . r e a d B y t e s ( I O B u f f e r . j a v a : 7 1 6 8 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . T D S C h a n n e l $ S S L H a n d s h a k e I n p u t S t r e a m . r e a d I n t e r n a l ( I O B u f f e r . j a v a : 9 5 3 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . T D S C h a n n e l $ S S L H a n d s h a k e I n p u t S t r e a m . r e a d ( I O B u f f e r . j a v a : 9 4 3 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . T D S C h a n n e l $ P r o x y I n p u t S t r e a m . r e a d I n t e r n a l ( I O B u f f e r . j a v a : 1 2 0 7 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . T D S C h a n n e l $ P r o x y I n p u t S t r e a m . r e a d ( I O B u f f e r . j a v a : 1 1 9 3 ) < b r   / >         a t   c o m . a n d r o i d . o r g . c o n s c r y p t . C o n s c r y p t E n g i n e S o c k e t $ S S L I n p u t S t r e a m . r e a d F r o m S o c k e t ( C o n s c r y p t E n g i n e S o c k e t . j a v a : 9 8 3 ) < b r   / >         a t   c o m . a n d r o i d . o r g . c o n s c r y p t . C o n s c r y p t E n g i n e S o c k e t $ S S L I n p u t S t r e a m . p r o c e s s D a t a F r o m S o c k e t ( C o n s c r y p t E n g i n e S o c k e t . j a v a : 9 4 7 ) < b r   / >         a t   c o m . a n d r o i d . o r g . c o n s c r y p t . C o n s c r y p t E n g i n e S o c k e t $ S S L I n p u t S t r e a m . - $ $ N e s t $ m p r o c e s s D a t a F r o m S o c k e t ( U n k n o w n   S o u r c e : 0 ) < b r   / >         a t   c o m . a n d r o i d . o r g . c o n s c r y p t . C o n s c r y p t E n g i n e S o c k e t . d o H a n d s h a k e ( C o n s c r y p t E n g i n e S o c k e t . j a v a : 2 3 6 ) < b r   / >         a t   c o m . a n d r o i d . o r g . c o n s c r y p t . C o n s c r y p t E n g i n e S o c k e t . s t a r t H a n d s h a k e ( C o n s c r y p t E n g i n e S o c k e t . j a v a : 2 1 8 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . T D S C h a n n e l . e n a b l e S S L ( I O B u f f e r . j a v a : 1 8 5 5 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . S Q L S e r v e r C o n n e c t i o n . c o n n e c t H e l p e r ( S Q L S e r v e r C o n n e c t i o n . j a v a : 3 8 1 4 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . S Q L S e r v e r C o n n e c t i o n . l o g i n ( S Q L S e r v e r C o n n e c t i o n . j a v a : 3 4 0 2 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . S Q L S e r v e r C o n n e c t i o n . c o n n e c t I n t e r n a l ( S Q L S e r v e r C o n n e c t i o n . j a v a : 3 2 1 1 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . S Q L S e r v e r C o n n e c t i o n . c o n n e c t ( S Q L S e r v e r C o n n e c t i o n . j a v a : 1 9 7 9 ) < b r   / >         a t   c o m . m i c r o s o f t . s q l s e r v e r . j d b c . S Q L S e r v e r D r i v e r . c o n n e c t ( S Q L S e r v e r D r i v e r . j a v a : 1 2 6 7 ) < b r   / >         a t   j a v a . s q l . D r i v e r M a n a g e r . g e t C o n n e c t i o n ( D r i v e r M a n a g e r . j a v a : 5 8 0 ) < b r   / >         a t   j a v a . s q l . D r i v e r M a n a g e r . g e t C o n n e c t i o n ( D r i v e r M a n a g e r . j a v a : 2 1 8 ) < b r   / >         a t   o r g . j e t b r a i n s . e x p o s e d . s q l . D a t a b a s e $ C o m p a n i o n . c o n n e c t $ l a m b d a $ 1 5 ( D a t a b a s e . k t : 2 8 7 ) < b r   / >         a t   o r g . j e t b r a i n s . e x p o s e d . s q l . D a t a b a s e $ C o m p a n i o n . $ r 8 $ l a m b d a $ m E H B W F m Z Q 2 g R K 5 Z H c U c - r 3 a P d O 4 ( U n k n o w n   S o u r c e : 0 ) < b r   / >         a t   o r g . j e t b r a i n s . e x p o s e d . s q l . D a t a b a s e $ C o m p a n i o n $ $ E x t e r n a l S y n t h e t i c L a m b d a 5 . i n v o k e ( D 8 $ $ S y n t h e t i c C l a s s : 0 ) < b r   / >         a t   o r g . j e t b r a i n s . e x p o s e d . s q l . D a t a b a s e $ C o m p a n i o n . d o C o n n e c t $ l a m b d a $ 3 ( D a t a b a s e . k t : 1 6 5 ) < b r   / >         a t   o r g . j e t b r a i n s . e x p o s e d . s q l . D a t a b a s e $ C o m p a n i o n . $ r 8 $ l a m b d a $ M 4 U P 1 7 S W 6 9 m g Z 6 0 a m K E C b 4 I L Q E A ( U n k n o w n   S o u r c e : 0 ) < b r   / >         a t   o r g . j e t b r a i n s . e x p o s e d . s q l . D a t a b a s e $ C o m p a n i o n $ $ E x t e r n a l S y n t h e t i c L a m b d a 1 2 . i n v o k e ( D 8 $ $ S y n t h e t i c C l a s s : 0 ) < b r   / >         a t   o r g . j e t b r a i n s . e x p o s e d . s q l . t r a n s a c t i o n s . T h r e a d L o c a l T r a n s a c t i o n M a n a g e r $ T h r e a d L o c a l T r a n s a c t i o n . c o n n e c t i o n L a z y $ l a m b d a $ 2 ( T h r e a d L o c a l T r a n s a c t i o n M a n a g e r . k t : 1 3 8 ) < b r   / >         a t   o r g . j e t b r a i n s.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction.$r8$lambda$t9ZtbVA_79RBbPMP0NEp6XRjTlU(Unknown Source:0)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0)
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction.getConnection(ThreadLocalTransactionManager.kt:163)
at org.jetbrains.exposed.sql.Transaction.getConnection(Unknown Source:2)
at org.jetbrains.exposed.sql.statements.Statement.prepared(Statement.kt:46)
at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_core(Statement.kt:79)
at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:292)
at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:269)
at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:235)
at org.jetbrains.exposed.sql.Transaction.exec$default(Transaction.kt:223)
at com.example.barcodescanningm3.data.repository.DBRepository$ensureTableExists$2.invokeSuspend$lambda$3(DBRepository.kt:41)

at com.example.barcodescanningm3.data.repository.DBRepository$ensureTableExists$2.$r8$lambda$k4755KZv3AIYPTdnxsj5WSbEMvs(Unknown Source:0)
at com.example.barcodescanningm3.data.repository.DBRepository$ensureTableExists$2$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction$run(ThreadLocalTransactionManager.kt:334)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction$lambda$10(ThreadLocalTransactionManager.kt:381)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.$r8$lambda$Gk1vyoDXU27VaM6Az7NTZXYouWA(Unknown Source:0)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$$ExternalSyntheticLambda1.invoke(D8$$SyntheticClass:0)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:389)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:380)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction$lambda$4(ThreadLocalTransactionManager.kt:289)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.$r8$lambda$aTLrtOoqP27z7BT_U8gXwZaruhU(Unknown Source:0)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$$ExternalSyntheticLambda2.invoke(D8$$SyntheticClass:0)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:389)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:249)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:227)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction$default(ThreadLocalTransactionManager.kt:226)
at com.example.barcodescanningm3.data.repository.DBRepository$ensureTableExists$2.invokeSuspend(DBRepository.kt:39)
at com.example.barcodescanningm3.data.repository.DBRepository$ensureTableExists$2.invoke(Unknown Source:8)
at com.example.barcodescanningm3.data.repository.DBRepository$ensureTableExists$2.invoke(Unknown Source:4)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:61)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:163)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
at com.example.barcodescanningm3.data.repository.DBRepository.ensureTableExists(DBRepository.kt:37)
at com.example.barcodescanningm3.viewmodel.DBViewModel$checkIfTableExists$1.invokeSuspend(DBViewModel.kt:17)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)
Suppressed:  kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@58e0d7f, Dispatchers.IO]
Я не совсем понимаю проблему, поэтому пытаюсь все изменить. Я изменил отправляемый URL-адрес, изменил операции, способ использования Couroutines и т. д. Но ничего из этого не сработало. Я думаю, что решение, вероятно, легко найти, но сейчас я застрял.

Подробнее здесь: https://stackoverflow.com/questions/790 ... mmsgssent1
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»