gpt4 book ai didi

java - Android 中的 JGraphT 实现

转载 作者:行者123 更新时间:2023-12-01 19:09:56 27 4
gpt4 key购买 nike

我将 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com