java - Android 中的 JGraphT 实现

标签 java android graph jgrapht

我将 JGraphT 实现到 Android 应用程序中。

我已将所需的所有内容添加到 Gradle 中,之后我想将一些示例放入代码中:

        SimpleDirectedWeightedGraph<String, DefaultWeightedEdge> topoGraph =
                new SimpleDirectedWeightedGraph<String, DefaultWeightedEdge>(DefaultWeightedEdge.class);
        topoGraph.addVertex("Rysy");
        topoGraph.addVertex("Giewont");

        DefaultWeightedEdge e1 = topoGraph.addEdge("Rysy", "Giewont");
        DefaultWeightedEdge e2 = topoGraph.addEdge("Giewont", "Rysy");

        topoGraph.setEdgeWeight(e1, 200);
        topoGraph.setEdgeWeight(e2, 400);

当我想启动我的应用程序时,出现错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.mountaintraveller, PID: 9857
    java.lang.BootstrapMethodError: Exception from call site #226 bootstrap method
        at org.jgrapht.util.SupplierUtil.createSupplier(SupplierUtil.java:60)
        at org.jgrapht.util.SupplierUtil.<clinit>(SupplierUtil.java:38)
        at org.jgrapht.util.SupplierUtil.createSupplier(SupplierUtil.java:60)
        at org.jgrapht.graph.SimpleDirectedWeightedGraph.<init>(SimpleDirectedWeightedGraph.java:45)
        at com.example.mountaintraveller.MainActivity.onCreate(MainActivity.java:84)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassCastException: Bootstrap method returned null
        at org.jgrapht.util.SupplierUtil.createSupplier(SupplierUtil.java:60) 
        at org.jgrapht.util.SupplierUtil.<clinit>(SupplierUtil.java:38) 
        at org.jgrapht.util.SupplierUtil.createSupplier(SupplierUtil.java:60) 
        at org.jgrapht.graph.SimpleDirectedWeightedGraph.<init>(SimpleDirectedWeightedGraph.java:45) 
        at com.example.mountaintraveller.MainActivity.onCreate(MainActivity.java:84) 
        at android.app.Activity.performCreate(Activity.java:7136) 
        at android.app.Activity.performCreate(Activity.java:7127) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

其中行:at org.jgrapht.graph.SimpleDirectedWeightedGraph.(SimpleDirectedWeightedGraph.java:45) 来自图问题。

我无法理解“调用站点 #226 bootstrap 方法的异常”的含义。

最佳答案

我已找到此错误的解决方案。 所需的一切:

打开您的 Gradle 文件并插入:

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

在 android { ... } 选项内。

关于java - Android 中的 JGraphT 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59491672/

相关文章:

android - 用户/开发人员如何为 2.x 版本设置 Android 的代理配置?

java - Andrjoid JNI简单,接下来返回错误

c - 使用 C 语言绘制 x-y 图

graph - IDA 用什么来作图?

java - 为什么Java不支持在finally抛出异常时从try/catch lost中检索异常?

Android项目报错! "Conversion to Dalvik format failed with error 1"

java - 在Java中使用继承时如何避免重复使用代码?

javascript - GunDB SEA 让其他用户写入用户空间

java - 为什么 Java 在尝试打印大随机数时报告不匹配?

java - 如何从循环语句内的用户获取字符串或整数数组?