- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
有时在编译项目时出现此错误:
Error:java.lang.UnsupportedOperationException: Unresolved local class: com/myproject/activities/BaseActivity$broadcastReceiver$1
at org.jetbrains.kotlin.descriptors.NotFoundClasses$classes$1.invoke(NotFoundClasses.kt:44)
at org.jetbrains.kotlin.descriptors.NotFoundClasses$classes$1.invoke(NotFoundClasses.kt:32)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:408)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:483)
at org.jetbrains.kotlin.descriptors.NotFoundClasses.getClass(NotFoundClasses.kt:101)
at org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer$typeConstructor$1.invoke(TypeDeserializer.kt:120)
at org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer.typeConstructor(TypeDeserializer.kt:124)
at org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer.simpleType(TypeDeserializer.kt:82)
at org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer.type(TypeDeserializer.kt:70)
at org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer.type$default(TypeDeserializer.kt:62)
at org.jetbrains.kotlin.serialization.deserialization.MemberDeserializer.loadProperty(MemberDeserializer.kt:67)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope.computeProperties(DeserializedMemberScope.kt:123)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope.access$computeProperties(DeserializedMemberScope.kt:35)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope$properties$1.invoke(DeserializedMemberScope.kt:61)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope$properties$1.invoke(DeserializedMemberScope.kt:35)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:408)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:483)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope.getContributedVariables(DeserializedMemberScope.kt:137)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassMemberScope.getContributedVariables(DeserializedClassDescriptor.kt:232)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassMemberScope.computeNonDeclaredProperties(DeserializedClassDescriptor.kt:252)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope.computeProperties(DeserializedMemberScope.kt:124)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope.access$computeProperties(DeserializedMemberScope.kt:35)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope$properties$1.invoke(DeserializedMemberScope.kt:61)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope$properties$1.invoke(DeserializedMemberScope.kt:35)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:408)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:483)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope.getContributedVariables(DeserializedMemberScope.kt:137)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassMemberScope.getContributedVariables(DeserializedClassDescriptor.kt:232)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope.addFunctionsAndProperties(DeserializedMemberScope.kt:185)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope.computeDescriptors(DeserializedMemberScope.kt:153)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassMemberScope$allDescriptors$1.invoke(DeserializedClassDescriptor.kt:218)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassMemberScope$allDescriptors$1.invoke(DeserializedClassDescriptor.kt:211)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:323)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(LockBasedStorageManager.java:370)
at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassMemberScope.getContributedDescriptors(DeserializedClassDescriptor.kt:223)
at org.jetbrains.kotlin.resolve.scopes.ResolutionScope$DefaultImpls.getContributedDescriptors$default(ResolutionScope.kt:40)
at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope.computeExtraDescriptors(LazyClassMemberScope.kt:71)
at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope$extraDescriptors$1.invoke(LazyClassMemberScope.kt:58)
at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope$extraDescriptors$1.invoke(LazyClassMemberScope.kt:47)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:323)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(LockBasedStorageManager.java:370)
at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope.getContributedDescriptors(LazyClassMemberScope.kt:64)
at org.jetbrains.kotlin.resolve.DescriptorUtils.getAllDescriptors(DescriptorUtils.java:578)
at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor.resolveMemberHeaders(LazyClassDescriptor.java:569)
at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor.doForceResolveAllContents(LazyClassDescriptor.java:539)
at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor.lambda$new$4(LazyClassDescriptor.java:229)
at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:323)
at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor.forceResolveAllContents(LazyClassDescriptor.java:535)
at org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil.doForceResolveAllContents(ForceResolveUtil.java:75)
at org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil.forceResolveAllContents(ForceResolveUtil.java:41)
at org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension$doAnalysis$1.invoke(PartialAnalysisHandlerExtension.kt:66)
at org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension$doAnalysis$1.invoke(PartialAnalysisHandlerExtension.kt:34)
at org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension.doForEachDeclaration(PartialAnalysisHandlerExtension.kt:119)
at org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension.doForEachDeclaration(PartialAnalysisHandlerExtension.kt:133)
at org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension.doAnalysis(PartialAnalysisHandlerExtension.kt:61)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.doAnalysis(Kapt3Extension.kt:145)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:104)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:83)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:376)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:67)
at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:96)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:367)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:132)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:158)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:61)
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:92)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:353)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:86)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:213)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:83)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.execIncrementalCompiler(CompileServiceImpl.kt:515)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execIncrementalCompiler(CompileServiceImpl.kt:96)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:399)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:96)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:892)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:96)
at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:919)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:891)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:398)
at sun.reflect.GeneratedMethodAccessor100.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)
我的 BaseActivity 是这样的:
abstract class BaseActivity : Activity {
companion object {
private const val LOG_TAG = "BaseActivity"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver,
IntentFilter(MY_FILTER))
}
override fun onStop() {
super.onStop()
if(isFinishing){
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver)
}
}
private val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) = when (intent?.action) {
MY_FILTER -> Log.d(LOG_TAG, "This is my filter!")
else -> Log.e(LOG_TAG, "Hello action ${intent?.action}")
}
}
}
Clean Project
和 Rebuild 解决了这个问题。
我仍然想了解为什么会发生这种情况,以及如何预防。
注意:我在使用没有 Proguard
或其他类似东西的调试风格时发生了这种情况。
最佳答案
解决方法是指定变量的确切类型,在这种情况下类型推断由于某种原因(可能是 Kotlin 错误)不起作用。
所以不要这样:
private val broadcastReceiver = object : BroadcastReceiver()
使用这个:
private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver()
关于android - Kotlin:在 Activity 中使用 BroadcastReceiver 时未解析的本地类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48454025/
我的应用程序无法在 Android 7 上运行。调用了我的 BroadcastReceiver.onReceive 方法,但缺少 intent.getExtras 的内容。我已验证数据已正确加载。这是
我认为即使我退出应用程序,BroadcastReceiver AlarmManagerBroadcastReceiver 也会继续运行。我认为 BroadcastReceiver 会在我重新启动系统时
我为 Wi-Fi 创建了一个 brodcastReceiver,一切正常,除了,当我午餐应用程序时,broadcastreceiver 开始直接扫描,我无法停止它,即使我离开应用。我试图从主要 Act
我最近开始在我的 Android 应用程序上使用 Google Analytics(分析)。我想知道如何在 BroadcastReceiver 的 onReceive 方法中将事件发送到 GA。这是一
我想在 Broadcast Receiver 中检查互联网连接;并将结果( bool 标志)设置为全局变量,以便在 if 条件下将其用于整个应用程序;如果互联网断开连接,则在主要 Activity 中
如果用户向上或向下按下音量键,是否可以在我的广播接收器中检测到它?我需要完整的代码。 这是我的 Intent 过滤器 IntentFilter filter = new IntentFilter();
我正在尝试编写一个应用程序,其中我根据使用 gcm 推送通知发送的消息对 UI 进行更改,并且我设法通过使用 BroadcastReceiver onReceive 函数来实现它来实现它,但它仅在应用
我正在尝试使用 AlarmManager 安排通知当我安排一个通知时它工作得很好,但是当我安排两个通知时,第一个通知没问题,但第二个通知不起作用。 我发现几分钟后打开应用程序会通知第二个通知。我认为我
我正在阅读指南 here关于设置 BroadcastReceiver 来检查电池变化。它指出我可以像这样设置一个 BroadcastReceiver:
我想在应用程序中接收有关启用/禁用位置提供程序的信息,例如NETWORK、GPS等。我创建了简单的BroadcastReceiver: public class TestReciver extends
我正在使用广播接收器来设置警报警报,但由于某种原因它无法工作。 public class SimpleSleepActivity extends Activity { /** Called when
当我的应用程序处于后台时,我尝试播放一些音调,并按下“相机”按钮,因为我正在执行此简单的步骤。 创建BroadcastReceiver类 public class CameraButtonListen
我创建了我的广播接收器 AnprEventReciever,它应该在连接状态发生变化时被触发,但它并没有。 事件接收者: import android.content.BroadcastReceive
我有一个时间选择器来设置闹钟 public class TimePickerFragment : DialogFragment, TimePickerDialog.IOnTimeSetListener
我目前正在开发一个使用 broadcastreceiver 来检查收到的短信的应用程序,但突然间它似乎停止工作了,我什至写了一个小的测试应用程序,以至少对我来说,语法上似乎是正确的,但也不起作用。 这
我正在尝试使用 BroadcastReceiver 获取互联网连接状态。 接收类是这样的: public class ConnectivityReceiver extends BroadcastRec
我有一个小部件,它只使用服务来更新小部件的 RemoteView 的外观。该服务基于由不同注册的 BroadcastReceiver 提供的过滤器启动。当满足其中一个条件时,将调用我的 Broadca
我没有时间玩接收器,而且我对2.3.x以上的东西都不熟悉,所以当我读到这个问题时,我感到非常困惑: Can BroadcastReceiver registered in AndroidManifes
我有一个录音机 android 线程,我需要知道录音时麦克风/耳机是否已连接,所以我需要在线程内使用 BroadcastReceiver()。我如何注册它? this.registerReceiver
大家好,感谢您的帮助!我将从代码开始 所以,带有广播接收器的类是这样的: public class MyService extends Service { // ... // ACTI
我是一名优秀的程序员,十分优秀!