Я работаю над анализом файлов .csv, используя OpenCsv для моего приложения для Android. Я написал код в котлин.
Вот мой код:
Вот как я анализирую CSV-файл:
val beans: List<csvDataClass> = CsvToBeanBuilder<csvDataClass>(FileReader(file))
.withType(csvDataClass::class.java).build().parse()
for (i:Int in 0..beans.size-1) {
Log.d("Tag", " NAME = ${beans.get(i).name} Number = ${beans.get(i).phone_one_value}")
}
Это класс объектов, в который я хочу преобразовать данные CSV.
class csvDataClass {
@CsvBindByName (column = "Name")
var name:String = ""
@CsvBindByName (column = "Phone 1 - Value")
var phone_one_value:Int = 0
constructor() {}
constructor(name: String, phone_one_value: Int) {
this.name = name
this.phone_one_value = phone_one_value
}
}
Я добавил эту строку в файл build.gradle:
implementation 'com.opencsv:opencsv:4.1'
Вот содержимое моего csv-файла:
Name,Phone 1 - Value
G T, 11111 11111
H K, 22222 22222
К К, 33333 33333
P K, 44444 44444
Но когда я запускаю код, я получаю:
05-04 16:13:31.821 25829-25829/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pk.opencsvpoc, PID: 25829
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/beans/Introspector;
at com.opencsv.bean.HeaderColumnNameMappingStrategy.loadDescriptors(HeaderColumnNameMappingStrategy.java:372)
at com.opencsv.bean.HeaderColumnNameMappingStrategy.loadDescriptorMap(HeaderColumnNameMappingStrategy.java:284)
at com.opencsv.bean.HeaderColumnNameMappingStrategy.setType(HeaderColumnNameMappingStrategy.java:415)
at com.opencsv.bean.opencsvUtils.determineMappingStrategy(opencsvUtils.java:83)
at com.opencsv.bean.CsvToBeanBuilder.build(CsvToBeanBuilder.java:156)
at com.example.pardeepkumar.opencsvpoc.MainActivity.readCsvFile(MainActivity.kt:46)
at com.example.pardeepkumar.opencsvpoc.MainActivity.onCreate(MainActivity.kt:38)
at android.app.Activity.performCreate(Activity.java:6726)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.beans.Introspector" on path: DexPathList[[zip file "/data/app/com.example.pk.opencsvpoc-1/base.apk", zip file "/data/app/com.example.pk.opencsvpoc-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.pk.opencsvpoc-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.pk.opencsvpoc-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.pk.opencsvpoc-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.pk.opencsvpoc-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.pk.opencsvpoc-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.pk.opencsvpoc-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.pk.opencsvpoc-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.pk.opencsvpoc-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.pk.opencsvpoc-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.pk.opencsvpoc-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.pk.opencsvpoc-1/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.opencsv.bean.HeaderColumnNameMappingStrategy.loadDescriptors(HeaderColumnNameMappingStrategy.java:372)
at com.opencsv.bean.HeaderColumnNameMappingStrategy.loadDescriptorMap(HeaderColumnNameMappingStrategy.java:284)
at com.opencsv.bean.HeaderColumnNameMappingStrategy.setType(HeaderColumnNameMappingStrategy.java:415)
at com.opencsv.bean.opencsvUtils.determineMappingStrategy(opencsvUtils.java:83)
at com.opencsv.bean.CsvToBeanBuilder.build(CsvToBeanBuilder.java:156)
at com.example.pardeepkumar.opencsvpoc.MainActivity.readCsvFile(MainActivity.kt:46)
at com.example.pardeepkumar.opencsvpoc.MainActivity.onCreate(MainActivity.kt:38)
at android.app.Activity.performCreate(Activity.java:6726)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)