Hello i'm new in android developing and am doing a work for university, to create a app that can create graphs (of graph theory) and execute algorithms, I chose to use graphstream, because it is a graph library but i'm having some issues, I can't put the node on the View the layout is in a fragment because i'm using two activits one to draw the graph and the other to choose the algorithm. (this is just a test to see if the graph appear in the screen, I will try to implement the buttons so that the user creates his own graph).
this is my java code:
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();
}
}
this is my layout:
<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>
this is my bottomNavView that i'm trying to put an event to click and draw nodes and edges and delete them:
<?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>
and this is my error:
--------- 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.
My question is how to correct this ?, this is the best way to do this? thanks for read, plz help me.
You can't use Graphstream 1.3 and the regular display() method. If you want to develop an android application, you must use Graphstream 2.0 with the Android UI
You can find some example here to help you.