我无法在android应用程序中使用kafka producer。我得到以下例外情况。,
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.management.DynamicMBean" on path: DexPathList[[dex file "/data/data/com.a.kafkaproducer/files/instant-run/dex/slice-zookeeper-3.4.6_8a38f89467d40a18afbd8baad7b29088157e6083-classes.dex", dex file "/data/data/com.a.kafkaproducer/files/instant-run/dex/slice-zkclient-0.8_e811ffc59b2b86f143b12056ea3479df3f628d5a-classes.dex", dex file "/data/data/com.a.kafkaproducer/files/instant-run/dex/slice-support-annotations-25.1.0_c6c37b5425fad5a782cbe7db2279266099bc29a9-classes.dex", dex file "/data/data/com.a.kafkaproducer/files/instant-run/dex/slice-snappy-java-1.1.2.6_848c76c3e0ca3a9ed4d0c95a6eeba1e11cd43625-classes.dex", dex file "/data/data/com.a.kafkaproducer/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.a.kafkaproducer/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.a.kafkaproducer/files/instant-run/dex/slice-slice_7-classes.dex", dex file
`at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
I/art: at java.lang.Class
com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(java.lang.String) (IncrementalClassLoader.java:90)
I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
I/art: at java.lang.Class dalvik.system.DexFile.defineClassNative(java.lang.String, java.lang.ClassLoader, java.lang.Object, dalvik.system.DexFile) (DexFile.java:-2)
I/art: at java.lang.Class dalvik.system.DexFile.defineClass(java.lang.String, java.lang.ClassLoader, java.lang.Object, dalvik.system.DexFile, java.util.List) (DexFile.java:296)
I/art: at java.lang.Class dalvik.system.DexFile.loadClassBinaryName(java.lang.String, java.lang.ClassLoader, java.util.List) (DexFile.java:289)
I/art: at java.lang.Class dalvik.system.DexPathList.findClass(java.lang.String, java.util.List) (DexPathList.java:418)
I/art: at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:54)
I/art: at java.lang.Class com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(java.lang.String) (IncrementalClassLoader.java:90)
I/art: at java.lang.Class com.android.tools.fd.runtime.IncrementalClassLoader.findClass(java.lang.String) (IncrementalClassLoader.java:62)
I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:367)
I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:367)
I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
I/art: at void org.apache.kafka.clients.producer.KafkaProducer.<init>(org.apache.kafka.clients.producer.ProducerConfig, org.apache.kafka.common.serialization.Serializer, org.apache.kafka.common.serialization.Serializer) (KafkaProducer.java:223)
I/art: at void org.apache.kafka.clients.producer.KafkaProducer.<init>(java.util.Properties) (KafkaProducer.java:188)
I/art: at void com.nokia.kafkaproducer.Producer.<init>(java.lang.String, java.lang.Boolean) (Producer.java:29)
I/art: at void com.nokia.kafkaproducer.MainActivity$1.onClick(android.view.View) (MainActivity.java:35)
I/art: at boolean android.view.View.performClick() (View.java:5637)
I/art: at void android.view.View$PerformClick.run() (View.java:22429)
I/art: at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:751)
I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:95)
I/art: at void android.os.Looper.loop() (Looper.java:154)
I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6119)
I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:886)
I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:776)`
使用以下渐变依赖项:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
// https://mvnrepository.com/artifact/org.apache.kafka/kafka-clients
compile group: 'org.apache.kafka', name: 'kafka-clients', version: '0.10.1.1' testCompile 'junit:junit:3.8.1' }
我使用的是github repo中的producer示例
谢谢你的帮助
2条答案
按热度按时间ca1c2owp1#
kafka客户机库是根据java标准版开发的,java标准版
javax.management
包是的一部分。然而,这个包不是android使用的dalvik运行时的一部分,它只提供javaseapi的一个子集。您需要找到一个包含kafka使用的类的jar文件,并将其放入libs
项目的文件。lb3vh1jj2#
把它输入到你的版本中
希望有帮助:)