- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要使用 Volley 从 API 检索各种 JSONObject。 API 需要使用 Basic 进行 header 身份验证。如果我不添加 header ,它会起作用,但当我添加 header 时,我会不断收到 org.jetbrains.kotlin.codegen.CompilationException 。以下是我编写的函数:
private suspend fun readData(url: String): JSONObject = suspendCancellableCoroutine { continuation ->
val request: JsonObjectRequest = object: JsonObjectRequest(Request.Method.POST, url, null, Response.Listener<JSONObject> {
continuation.resume(it)
}, Response.ErrorListener {
continuation.resumeWithException(Exception(it.cause))
}) {
override fun getHeaders(): Map<String, String> = mapOf("Content-Type" to "application/json", "charset" to "utf-8", "Authorization" to "Basic ".plus(android.util.Base64.encode(String.format("%s:%s", getString(R.string.api_login_username), getString(R.string.api_login_password)).toByteArray(), android.util.Base64.DEFAULT)))
}
request.setShouldCache(false)
this.queue?.add(request)
}
fun data(url: String) = async(CommonPool) { readData(url) }
他们像这样实现它们:
val brands = data(getString(R.string.api_url).plus("/api/brand"))
val models = data(getString(R.string.api_url).plus("/api/model"))
launch(UI) {
val brandsJsonArray = brands.await().getJSONArray("recordset")
val modelsJsonArray = models.await().getJSONArray("recordset")
}
但这是我尝试编译项目时不断遇到的异常:
org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'suspendCoroutine' into
public final suspend fun readData(queue: com.android.volley.RequestQueue?, url: kotlin.String, continuation: kotlin.coroutines.experimental.Continuation<org.json.JSONObject>): kotlin.Any? defined in com.universales.inspeccion.activities.InspectionCreateActivity
suspend fun readData(url: String): JSONObject = suspendCancellableCoroutine { continuation ->
val request = object : JsonObjectRequest(Request.Method.GET, url, JSONObject(), Response.Listener {
continuation.resume(it)
}, Response.ErrorListener {
continuation.resumeWithException(Exception(it.cause))
}) {
override fun getHeaders(): Map<String, String> = mapOf("Content-Type" to "application/json", "charset" to "utf-8", "Authorization" to "Basic ".plus(android.util.Base64.encode(String.format("%s:%s", getString(R.string.api_login_username), getString(R.string.api_login_password)).toByteArray(), android.util.Base64.DEFAULT)))
}
queue?.add(request)
continuation.invokeOnCompletion {
request.cancel()
}
}
Cause: suspendCancellableCoroutine$default (ZLkotlin/jvm/functions/Function1;Lkotlin/coroutines/experimental/Continuation;ILjava/lang/Object;)Ljava/lang/Object;:
L0
L1
LINENUMBER 167 L1
ICONST_0
ISTORE 0
L2
LINENUMBER 297 L2
ICONST_0
INVOKESTATIC kotlin/jvm/internal/InlineMarker.mark (I)V
ALOAD 2
INVOKESTATIC kotlin/coroutines/experimental/jvm/internal/CoroutineIntrinsics.normalizeContinuation (Lkotlin/coroutines/experimental/Continuation;)Lkotlin/coroutines/experimental/Continuation;
ASTORE 4
L3
LINENUMBER 298 L3
NEW kotlinx/coroutines/experimental/CancellableContinuationImpl
DUP
ALOAD 4
ICONST_1
INVOKESPECIAL kotlinx/coroutines/experimental/CancellableContinuationImpl.<init> (Lkotlin/coroutines/experimental/Continuation;I)V
ASTORE 5
L4
LINENUMBER 299 L4
ILOAD 0
IFNE L5
ALOAD 5
INVOKEVIRTUAL kotlinx/coroutines/experimental/CancellableContinuationImpl.initCancellability ()V
L5
LINENUMBER 300 L5
ALOAD 1
ALOAD 5
INVOKEINTERFACE kotlin/jvm/functions/Function1.invoke (Ljava/lang/Object;)Ljava/lang/Object;
POP
L6
LINENUMBER 301 L6
ALOAD 5
INVOKEVIRTUAL kotlinx/coroutines/experimental/CancellableContinuationImpl.getResult ()Ljava/lang/Object;
L7
NOP
L8
LINENUMBER 297 L8
ICONST_1
INVOKESTATIC kotlin/jvm/internal/InlineMarker.mark (I)V
L9
LINENUMBER 302 L9
ARETURN
L10
LOCALVARIABLE cancellable Lkotlinx/coroutines/experimental/CancellableContinuationImpl; L4 L7 5
LOCALVARIABLE cont Lkotlin/coroutines/experimental/Continuation; L3 L8 4
LOCALVARIABLE $i$a$2$suspendCoroutineOrReturn I L3 L8 6
LOCALVARIABLE holdCancellability Z L2 L10 0
LOCALVARIABLE block Lkotlin/jvm/functions/Function1; L0 L10 1
LOCALVARIABLE $i$f$suspendCancellableCoroutine I L2 L10 3
MAXSTACK = 4
MAXLOCALS = 7
Cause: kotlin.KotlinNullPointerException
File being compiled at position: (124,75) in C:/Users/jcardama/Projects/android/inspeccion/app/src/main/java/com/universales/inspeccion/activities/InspectionCreateActivity.kt
The root cause was thrown at: MethodInliner.kt:280
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.throwCompilationException(InlineCodegen.kt:124)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:167)
at org.jetbrains.kotlin.codegen.inline.PsiInlineCodegen.genCallInner(InlineCodegen.kt:661)
at org.jetbrains.kotlin.codegen.CallGenerator$DefaultImpls.genCall(CallGenerator.kt:95)
at org.jetbrains.kotlin.codegen.inline.PsiInlineCodegen.genCall(InlineCodegen.kt:642)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2398)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2347)
at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:41)
at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:13)
at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:79)
at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:109)
at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:98)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.putStackValue(ExpressionCodegen.java:349)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:334)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.returnExpression(ExpressionCodegen.java:1621)
at org.jetbrains.kotlin.codegen.coroutines.SuspendFunctionGenerationStrategy.doGenerateBody(SuspendFunctionGenerationStrategy.kt:88)
at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$CodegenBased.generateBody(FunctionGenerationStrategy.java:80)
at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:620)
at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:391)
at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:244)
at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:168)
at org.jetbrains.kotlin.codegen.FunctionCodegen.gen(FunctionCodegen.java:139)
at org.jetbrains.kotlin.codegen.MemberCodegen.genSimpleMember(MemberCodegen.java:199)
at org.jetbrains.kotlin.codegen.ClassBodyCodegen.generateDeclaration(ClassBodyCodegen.java:161)
at org.jetbrains.kotlin.codegen.ClassBodyCodegen.generateBody(ClassBodyCodegen.java:75)
at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:131)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:305)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:289)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateClassOrObject(PackageCodegenImpl.java:161)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateClassesAndObjectsInFile(PackageCodegenImpl.java:86)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateFile(PackageCodegenImpl.java:119)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:66)
at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generatePackage(CodegenFactory.kt:97)
at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generateModule(CodegenFactory.kt:68)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.doGenerateFiles(KotlinCodegenFacade.java:47)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:39)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:454)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:150)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:161)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:63)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:107)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:96)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:463)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:98)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:228)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:38)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:90)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:102)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.execIncrementalCompiler(CompileServiceImpl.kt:538)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execIncrementalCompiler(CompileServiceImpl.kt:98)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:418)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:98)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:920)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:98)
at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:950)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:919)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:417)
at sun.reflect.GeneratedMethodAccessor102.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: kotlin.KotlinNullPointerException
at org.jetbrains.kotlin.codegen.inline.MethodInliner$doInline$lambdaInliner$1.visitMethodInsn(MethodInliner.kt:280)
at org.jetbrains.org.objectweb.asm.tree.MethodInsnNode.accept(MethodInsnNode.java:133)
at org.jetbrains.org.objectweb.asm.tree.InsnList.accept(InsnList.java:162)
at org.jetbrains.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:817)
at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:351)
at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:93)
at org.jetbrains.kotlin.codegen.inline.MethodInliner.access$doInline(MethodInliner.kt:39)
at org.jetbrains.kotlin.codegen.inline.MethodInliner$doInline$lambdaInliner$1.visitMethodInsn(MethodInliner.kt:259)
at org.jetbrains.org.objectweb.asm.tree.MethodInsnNode.accept(MethodInsnNode.java:133)
at org.jetbrains.org.objectweb.asm.tree.InsnList.accept(InsnList.java:162)
at org.jetbrains.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:817)
at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:351)
at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:93)
at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.kt:66)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.inlineCall(InlineCodegen.kt:278)
at org.jetbrains.kotlin.codegen.inline.InlineCodegen.performInline(InlineCodegen.kt:158)
... 73 more
最佳答案
将对象:JsonObjectRequest
的定义推送到一个命名类,该类将延续作为构造函数参数。这样,您就可以使 suspendCancellableCoroutine
内的代码更简单,并避免此编译器错误。
suspend fun readData(url: String): JSONObject = suspendCancellableCoroutine { continuation ->
RequestWithHeaders(url, continuation).also {
it.setShouldCache(false)
queue.add(it)
}
}
class RequestWithHeaders(
url: String,
continuation: Continuation<JSONObject>
) : JsonObjectRequest(Request.Method.POST, url, null, Response.Listener {
continuation.resume(it)
}, Response.ErrorListener {
continuation.resumeWithException(Exception(it.cause))
}) {
override fun getHeaders(): Map<String, String> = mapOf(
"Content-Type" to "application/json; charset=utf-8",
"Authorization" to "Basic")
}
关于android - Volley Kotlin 协程抛出 CompilationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50239684/
来自 java docs 公共(public) FileWriter(String fileName) 抛出 IOException 抛出: IOException - 如果指定的文件存在但它是目录而
我使用以下代码将我的 .net 客户端(基于 CQL)连接到 3 节点 Cassandra 集群。我以 30 条记录/秒的速度(从 RabbitMQ)获取数据,并且它们顺利地存储在 cassandra
如果在读取文件时缺少字段,我应该捕获 NoSuchElementException。如果缺少一个字段,我只需要跳到文件的下一行。我的问题是,我在哪里实现我的 try/catch 代码来做到这一点?这是
我正在尝试使用 ASP.NET MVC 实现 OpeinID 登录。我正在尝试按照 http://blog.nerdbank.net/2008/04/add-openid-login-support-
学习使用 Java 进行 xml 解析,并且正在编写一个测试程序来尝试各种东西。所有测试 System.out.println() 都是我在控制台中所期望的,除了 childElement 返回 [n
我正在尝试使用 SwingUtilities 创建 JFrame Thread tt = new Thread(new Runnable() { public void run
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我写了这段代码: MethodInfo method2 = typeof(IntPtr).GetMethod( "op_Explicit", Bind
我开始学习 Java,并且正在根据书本做一些练习。在执行此操作时,我遇到了以下错误:线程“main”java.util.InputMismatchException 中出现异常。我正在编写一个简单的程
我有一个文本文件,其中前两行是整数 m 和 n,然后有 m 行,每行都有 n 管道分隔值。我编写了一个程序,读取文件并使用文件中的值创建 m*n 数组,它工作了无数次,然后突然,使用相同的代码,使用相
所以我尝试使用在另一个类中生成的 bean 以在主应用程序中使用 package com.simon.spring.basics.properties; import org.spri
我还没有完成这个应用程序,但我希望在我的手机上看到它的样子。但是,它会强制关闭并引发 InstantiationException。 logcat 异常: 09-19 20:13:47.987: D/
我想从 UIViewController 加载一个基于 SwiftUI 的 View ,该 View 读取包本地的 json。仅 swiftUI 项目中的代码和绑定(bind)工作正常,当我利用 UI
'java.net.SocketTimeoutException:连接超时' 循环一段时间后我收到此错误。为什么我会收到 SocketTimeoutException?我该如何修复这个错误? @Ove
当有 null 值时抛出 ArgumentNullException() 是个好主意吗? This thread 没有提到在 null 上抛出的最明显的异常。 谢谢 最佳答案 ArgumentNull
我得到这个异常: NullReferenceException Object reference not set to an instance of an object at Namespace
所以其中一个方法的描述如下: public BasicLinkedList addToFront(T data) This operation is invalid for a sorted list
我正在使用 Intellij Idea,当我去生成 JavaDocs(通过工具 -> 生成 JavaDoc)时,我抛出了一个 IllegealArgumentException,没有关于发生了什么问题
我正在学习 C++ 中的互斥锁,但以下代码(摘自 N. Josuttis 的“C++ 标准库”)有问题。 我不明白为什么它会阻塞/抛出除非我在主线程中添加this_thread::sleep_for(
我正在试验 JavaFX 标签和组,通过鼠标拖动将它们移动到屏幕上。新节点从一些线程添加到动画组。但是,有时我会突然看到以下异常 - 我假设,当某些节点重叠时。但是不知道是什么问题……因为不涉及我的代
我是一名优秀的程序员,十分优秀!