I have a problem using PythonInterpreter in Android Studio somehow it keeps crashing the app and I don't understand the error and how to solve it.
Ich habe ein Problem den PythonInterpreter in Android Studio zu nutzen, irgendwie sorgt alleine die Initialisierung einer PythonInterpreter variable für Probleme ohne das es mir Syntax error anzeigt. Ich habe allerdings keine Ahnung wie ich das Problem lösen kann.
Der error:
Der Code sieht so aus
}
und falls es wichtig ist ich hatte vorher einen Fehler der so aussah:
8
den ich dann gelöst habe in dem ich das folgende snippet zu meinem build.gradle file hinzugefügt habe:
Meine Java version ist 1.8 und die der android Sdk ist 33, falls das relevant sein sollte.
Vielen Dank schonmal für jede Hilfe und Idee wie ich das lösen kann.
Ich habe ein Problem den PythonInterpreter in Android Studio zu nutzen, irgendwie sorgt alleine die Initialisierung einer PythonInterpreter variable für Probleme ohne das es mir Syntax error anzeigt. Ich habe allerdings keine Ahnung wie ich das Problem lösen kann.
Der error:
Java:
Process: com.example.signlanguageinterpreter, PID: 11601
java.lang.NoClassDefFoundError: Failed resolution of:
Ljava/lang/ClassValue;
at org.python.core.PyType.fromClass(PyType.java:2137)
at org.python.core.PyObject.<init>(PyObject.java:85)
at
org.python.core.PyBuiltinCallable.<init>(PyBuiltinCallable.java:22)
at org.python.core.PyBuiltinMethod.<init>(PyBuiltinMethod.java:16)
at org.python.core.PyBuiltinMethod.<init>(PyBuiltinMethod.java:21)
at org.python.core.PyType$type___init___exposer.<init>(Unknown
Source:0)
at org.python.core.PyType$PyExposer.<init>(Unknown Source:16)
at org.python.core.PyType.<clinit>(Unknown Source:2)
at org.python.core.PyType.fromClass(PyType.java:2137)
at org.python.core.PyObject.<init>(PyObject.java:85)
at
org.python.core.PyBuiltinCallable.<init>(PyBuiltinCallable.java:22)
at org.python.core.PyBuiltinMethod.<init>(PyBuiltinMethod.java:16)
at
org.python.core.PyBuiltinMethodNarrow.<init>(PyBuiltinMethodNarrow.java:23)
at
org.python.core.PyDataDescr$getset_descriptor___get___exposer.<init>(Unknown
Source:2)
at org.python.core.PyDataDescr$PyExposer.<init>(Unknown Source:15)
at org.python.core.PyDataDescr.<clinit>(Unknown Source:2)
at org.python.core.PyBuiltinCallable$PyExposer.<init>(Unknown
Source:14)
at org.python.core.PyBuiltinCallable.<clinit>(Unknown Source:2)
at org.python.core.PyObject$PyExposer.<init>(Unknown Source:13)
at org.python.core.PyObject.<clinit>(Unknown Source:2)
at org.python.core.PyNone.getInstance(PyNone.java:28)
at org.python.core.Py.<clinit>(Py.java:60)
at org.python.core.Py.newStringMap(Py.java:866)
at
org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:99)
at
org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:93)
at
org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:70)
at
com.example.signlanguageinterpreter.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:8057)
at android.app.Activity.performCreate(Activity.java:8037)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1341)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3688)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3864)
at
android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at
android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at
android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2253)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7870)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.ClassNotFoundException: Didn't find class
"java.lang.ClassValue" on path: DexPathList[[dex file
"/data/data/com.example.signlanguageinterpreter/code_cache/.overlay/base.apk/classes3.dex",
zip file
"/data/app/~~41ZZYylVPeerdWnpztRw6A==/com.example.signlanguageinterpreter-SZB2ZeTr5h5GJgq_1xUSyw==/base.apk"],nativeLibraryDirectories=[/data/app/~~41ZZYylVPeerdWnpztRw6A==/com.example.signlanguageinterpreter-SZB2ZeTr5h5GJgq_1xUSyw==/lib/x86_64,
/system/lib64, /system_ext/lib64]]
at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at org.python.core.PyType.fromClass(PyType.java:2137)
at org.python.core.PyObject.<init>(PyObject.java:85)
at
org.python.core.PyBuiltinCallable.<init>(PyBuiltinCallable.java:22)
at org.python.core.PyBuiltinMethod.<init>(PyBuiltinMethod.java:16)
at org.python.core.PyBuiltinMethod.<init>(PyBuiltinMethod.java:21)
at org.python.core.PyType$type___init___exposer.<init>(Unknown
Source:0)
at org.python.core.PyType$PyExposer.<init>(Unknown Source:16)
at org.python.core.PyType.<clinit>(Unknown Source:2)
at org.python.core.PyType.fromClass(PyType.java:2137)
at org.python.core.PyObject.<init>(PyObject.java:85)
at
org.python.core.PyBuiltinCallable.<init>(PyBuiltinCallable.java:22)
at org.python.core.PyBuiltinMethod.<init>(PyBuiltinMethod.java:16)
at
org.python.core.PyBuiltinMethodNarrow.<init>(PyBuiltinMethodNarrow.java:23)
at
org.python.core.PyDataDescr$getset_descriptor___get___exposer.<init>(Unknown
Source:2)
at org.python.core.PyDataDescr$PyExposer.<init>(Unknown Source:15)
at org.python.core.PyDataDescr.<clinit>(Unknown Source:2)
at org.python.core.PyBuiltinCallable$PyExposer.<init>(Unknown
Source:14)
at org.python.core.PyBuiltinCallable.<clinit>(Unknown Source:2)
at org.python.core.PyObject$PyExposer.<init>(Unknown Source:13)
at org.python.core.PyObject.<clinit>(Unknown Source:2)
at org.python.core.PyNone.getInstance(PyNone.java:28)
at org.python.core.Py.<clinit>(Py.java:60)
at org.python.core.Py.newStringMap(Py.java:866)
at
org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:99)
at
org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:93)
at
org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:70)
at
com.example.signlanguageinterpreter.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:8057)
at android.app.Activity.performCreate(Activity.java:8037)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1341)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3688)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3864)
at
android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at
android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at
android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2253)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7870)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Der Code sieht so aus
Java:
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity {
HashMap model_dict = new HashMap();
PythonInterpreter interpreter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
interpreter = new PythonInterpreter(); // hier crashed das Programm
interpreter.execfile("/home/PycharmProjects/SignLanguage_State2/inference_classifier.py");
PyObject getAtrsFunc = interpreter.get("main");
PyObject funcRes = getAtrsFunc.__call__();
model_dict = (HashMap) funcRes.__tojava__(HashMap.class);
}
und falls es wichtig ist ich hatte vorher einen Fehler der so aussah:
8
Code:
files found with path 'META-INF/INDEX.LIST'.
Adding a packagingOptions block may help, please refer to
https://developer.android.com/reference/tools/gradle-api/8.0/com/android/build/api/dsl/ResourcesPackagingOptions
for more information
den ich dann gelöst habe in dem ich das folgende snippet zu meinem build.gradle file hinzugefügt habe:
Java:
packagingOptions {
pickFirst "META-INF/INDEX.LIST"
pickFirst "META-INF/io.netty.versions.properties"
}
Meine Java version ist 1.8 und die der android Sdk ist 33, falls das relevant sein sollte.
Vielen Dank schonmal für jede Hilfe und Idee wie ich das lösen kann.