How can I use the class ViewControlLayer to change the Camera view or Map view?(Android Core)
The class ViewControlLayer http://docs.ros.org/indigo/api/android_apps/html/map__nav_2src_2main_2java_2com_8github_8rosjava_8android__apps_8map__nav_2ViewControlLayer_8java_source.html
Here is the Construction method:
public ViewControlLayer(final Context context,
final ExecutorService executorService,
final RosImageView<CompressedImage> cameraView,
final VisualizationView mapView,
final ViewGroup mainLayout,
final ViewGroup sideLayout,
final AppParameters params) {
this.context = context;
listeners = new ListenerGroup<CameraControlListener>(executorService);
this.cameraView = cameraView;
this.mapView = mapView;
this.mainLayout = mainLayout;
this.sideLayout = sideLayout;
viewMode = ViewMode.CAMERA;
this.cameraView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
swapViews();
}
});
this.mapView.setClickable(true);
this.cameraView.setClickable(false);
this.robotFrame = (String) params.get("robot_frame", context.getString(R.string.robot_frame));
mapViewGestureAvaiable = false;
}
This is my code(Method in onCreate()):
visualizationView.onCreate(Lists.<Layer>newArrayList(new CameraControlLayer(),
new OccupancyGridLayer("map"), new PathLayer("move_base/NavfnROS/plan"), new PathLayer(
"move_base_dynamic/NavfnROS/plan"), new LaserScanLayer("base_scan"),
new PoseSubscriberLayer("simple_waypoints_server/goal_pose"), new PosePublisherLayer(
"simple_waypoints_server/goal_pose"), new RobotLayer("base_footprint")));
I want to use the ViewControlLayer like this to change the Canera view or Map view,how can i do it?
(Method in init(NodeMainExecutor nodeMainExecutor))
visualizationView.onCreate(Lists.<Layer>newArrayList(new ViewControlLayer(this,
nodeMainExecutor.getScheduledExecutorService(), cameraView,
mapView, mainLayout, sideLayout, params),
new OccupancyGridLayer("map"), new PathLayer("move_base/NavfnROS/plan"), new PathLayer(
"move_base_dynamic/NavfnROS/plan"), new LaserScanLayer("base_scan"),
new PoseSubscriberLayer("simple_waypoints_server/goal_pose"), new PosePublisherLayer(
"simple_waypoints_server/goal_pose"), new RobotLayer("base_footprint")));
The error maybe occur at the ViewControlLayer Construction method:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.concurrent.ScheduledExecutorService org.ros.android.NodeMainExecutorService.getScheduledExecutorService()' on a null object reference at com.robot.et.myteleop.MainActivity.onCreate(MainActivity.java:65) at android.app.Activity.performCreate(Activity.java:6374) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2752) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2873) at android.app.ActivityThread.access$900(ActivityThread.java:181) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6145) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Asked by Tony10012 on 2016-07-17 02:40:24 UTC
Comments