java.lang.RuntimeException:无法启动查看器。 API GraphStream-Android
java.lang.RuntimeException: Cannot launch viewer. API GraphStream-Android
你好,我是 android 开发新手,正在为大学工作,创建一个可以创建图形(图论)和执行算法的应用程序,我选择使用 graphstream,因为它是一个图形库,但我遇到了一些问题,我无法将节点放在视图上
布局在一个片段中,因为我正在使用两个活动,一个用于绘制图形,另一个用于选择算法。 (这只是一个测试,看看图形是否出现在屏幕上,我会尝试实现按钮,以便用户创建自己的图形)。
这是我的 java 代码:
package com.projeto.gabriel.athenatgfinal;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.SingleGraph;
import org.graphstream.ui.android_viewer.DefaultView;
public class FragmentGrafo extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.grafo_fragment, container, false);
BottomNavigationView bottomNavigationView = view.findViewById(R.id.bottomNavView);
bottomNavigationView.setOnNavigationItemSelectedListener(selectedListener);
return view;
}
private BottomNavigationView.OnNavigationItemSelectedListener selectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add_node:
Toast.makeText(getActivity(), "Clicou em add nó", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_add_aresta:
Toast.makeText(getActivity(), "aresta aqui", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_remover:
Toast.makeText(getActivity(), "remover", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
};
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.setProperty("org.graphstream.ui.renderer","org.graphstream.ui.j2dviewer.J2DGraphRenderer");
Graph graph = new SingleGraph("tutorial 1");
graph.addNode("A" );
graph.addNode("B" );
graph.addNode("C" );
graph.addEdge("AB", "A", "B");
graph.addEdge("BC", "B", "C");
graph.addEdge("CA", "C", "A");
graph.display();
}
}
这是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<org.graphstream.ui.android_viewer.util.DefaultFragment
android:id="@+id/fragment_tag"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_above="@+id/bottomNavView"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="0dp"
android:layout_marginTop="369dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="287dp" />
<include layout="@layout/bottom_nav_view"
android:id="@+id/bottomNavView"/>
</RelativeLayout>
这是我的 bottomNavView,我正在尝试放置一个事件来单击并绘制节点和边并删除它们:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.BottomNavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@color/nav_item_color"
app:itemTextColor="@color/nav_item_color"
app:menu="@menu/menu_grafo">
</android.support.design.widget.BottomNavigationView>
这是我的错误:
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.projeto.gabriel.athenatgf, PID: 6000
java.lang.RuntimeException: Cannot launch viewer.
at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:212)
at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:204)
at com.projeto.gabriel.athenatgfinal.FragmentGrafo.onCreate(FragmentGrafo.java:67)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2414)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1418)
at android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1195)
at android.support.v4.app.FragmentTransition.calculateFragments(FragmentTransition.java:1078)
at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:117)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2408)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:146)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1244)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1092)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1622)
at android.view.View.measure(View.java:19857)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19857)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:19857)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19857)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:19857)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19857)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:690)
at android.view.View.measure(View.java:19857)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2275)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1366)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1619)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6338)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
at android.view.Choreographer.doCallbacks(Choreographer.java:686)
at android.view.Choreographer.doFrame(Choreographer.java:621)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6169)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)
Caused by: org.graphstream.util.MissingDisplayException: No UI package detected! Please use System.setProperty("org.graphstream.ui") for the selected package.
at org.graphstream.util.Display.getDefault(Display.java:55)
at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:209)
... 58 more
Application terminated.
我的问题是如何纠正这个问题?这是最好的方法吗?
感谢阅读,请帮助我。
您不能使用 Graphstream 1.3 和常规的 display() 方法。如果你想开发一个android应用程序,你必须使用Graphstream 2.0 with the Android UI
您可以找到一些示例 here 来帮助您。
你好,我是 android 开发新手,正在为大学工作,创建一个可以创建图形(图论)和执行算法的应用程序,我选择使用 graphstream,因为它是一个图形库,但我遇到了一些问题,我无法将节点放在视图上 布局在一个片段中,因为我正在使用两个活动,一个用于绘制图形,另一个用于选择算法。 (这只是一个测试,看看图形是否出现在屏幕上,我会尝试实现按钮,以便用户创建自己的图形)。
这是我的 java 代码:
package com.projeto.gabriel.athenatgfinal;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.SingleGraph;
import org.graphstream.ui.android_viewer.DefaultView;
public class FragmentGrafo extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.grafo_fragment, container, false);
BottomNavigationView bottomNavigationView = view.findViewById(R.id.bottomNavView);
bottomNavigationView.setOnNavigationItemSelectedListener(selectedListener);
return view;
}
private BottomNavigationView.OnNavigationItemSelectedListener selectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add_node:
Toast.makeText(getActivity(), "Clicou em add nó", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_add_aresta:
Toast.makeText(getActivity(), "aresta aqui", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_remover:
Toast.makeText(getActivity(), "remover", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
};
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.setProperty("org.graphstream.ui.renderer","org.graphstream.ui.j2dviewer.J2DGraphRenderer");
Graph graph = new SingleGraph("tutorial 1");
graph.addNode("A" );
graph.addNode("B" );
graph.addNode("C" );
graph.addEdge("AB", "A", "B");
graph.addEdge("BC", "B", "C");
graph.addEdge("CA", "C", "A");
graph.display();
}
}
这是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<org.graphstream.ui.android_viewer.util.DefaultFragment
android:id="@+id/fragment_tag"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_above="@+id/bottomNavView"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="0dp"
android:layout_marginTop="369dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="287dp" />
<include layout="@layout/bottom_nav_view"
android:id="@+id/bottomNavView"/>
</RelativeLayout>
这是我的 bottomNavView,我正在尝试放置一个事件来单击并绘制节点和边并删除它们:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.BottomNavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@color/nav_item_color"
app:itemTextColor="@color/nav_item_color"
app:menu="@menu/menu_grafo">
</android.support.design.widget.BottomNavigationView>
这是我的错误:
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.projeto.gabriel.athenatgf, PID: 6000 java.lang.RuntimeException: Cannot launch viewer. at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:212) at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:204) at com.projeto.gabriel.athenatgfinal.FragmentGrafo.onCreate(FragmentGrafo.java:67) at android.support.v4.app.Fragment.performCreate(Fragment.java:2414) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1418) at android.support.v4.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1195) at android.support.v4.app.FragmentTransition.calculateFragments(FragmentTransition.java:1078) at android.support.v4.app.FragmentTransition.startTransitions(FragmentTransition.java:117) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2408) at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366) at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243) at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654) at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:146) at android.support.v4.view.ViewPager.populate(ViewPager.java:1244) at android.support.v4.view.ViewPager.populate(ViewPager.java:1092) at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1622) at android.view.View.measure(View.java:19857) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) at android.view.View.measure(View.java:19857) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143) at android.view.View.measure(View.java:19857) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) at android.view.View.measure(View.java:19857) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.view.View.measure(View.java:19857) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) at android.view.View.measure(View.java:19857) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at com.android.internal.policy.DecorView.onMeasure(DecorView.java:690) at android.view.View.measure(View.java:19857) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2275) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1366) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1619) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6338) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874) at android.view.Choreographer.doCallbacks(Choreographer.java:686) at android.view.Choreographer.doFrame(Choreographer.java:621) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6169) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781) Caused by: org.graphstream.util.MissingDisplayException: No UI package detected! Please use System.setProperty("org.graphstream.ui") for the selected package. at org.graphstream.util.Display.getDefault(Display.java:55) at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:209) ... 58 more Application terminated.
我的问题是如何纠正这个问题?这是最好的方法吗? 感谢阅读,请帮助我。
您不能使用 Graphstream 1.3 和常规的 display() 方法。如果你想开发一个android应用程序,你必须使用Graphstream 2.0 with the Android UI
您可以找到一些示例 here 来帮助您。