声明MapView(ArcGIS for Android)中心和缩放

时间:2015-08-18 13:19:24

标签: java android

我在java和ArcGIS for android中都很好。我想用org.apache.spark.SparkException: Task not serializable at org.apache.spark.util.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:166) at org.apache.spark.util.ClosureCleaner$.clean(ClosureCleaner.scala:158) at org.apache.spark.SparkContext.clean(SparkContext.scala:1623) at org.apache.spark.rdd.RDD.filter(RDD.scala:303) at services.gps.spark.GPSSparkServiceImpl$$anonfun$generateUserToStep$1.applyOrElse(GPSSparkServiceImpl.scala: 41) at services.gps.spark.GPSSparkServiceImpl$$anonfun$generateUserToStep$1.applyOrElse(GPSSparkServiceImpl.scala: 38) at scala.concurrent.Future$$anonfun$onSuccess$1.apply(Future.scala:117) at scala.concurrent.Future$$anonfun$onSuccess$1.apply(Future.scala:115) at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121) at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.pollAndExecAll(ForkJoinPool.java:1253) at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1346) at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) Caused by: java.io.NotSerializableException: org.apache.spark.SparkConf Serialization stack: - object not serializable (class: org.apache.spark.SparkConf, value: org.apache.spark.SparkConf@1b0321ae) - field (class: services.gps.spark.GPSSparkServiceImpl, name: conf, type: class org.apache.spark.SparkConf) - object (class services.gps.spark.GPSSparkServiceImpl, services.gps.spark.GPSSparkServiceImpl@458c4049) - field (class: services.gps.spark.GPSSparkServiceImpl$$anonfun$generateUserToStep$1, name: $outer, type: clas s services.gps.spark.GPSSparkServiceImpl) - object (class services.gps.spark.GPSSparkServiceImpl$$anonfun$generateUserToStep$1, <function1>) - field (class: services.gps.spark.GPSSparkServiceImpl$$anonfun$generateUserToStep$1$$anonfun$3, name: $outer, type: class services.gps.spark.GPSSparkServiceImpl$$anonfun$generateUserToStep$1) - object (class services.gps.spark.GPSSparkServiceImpl$$anonfun$generateUserToStep$1$$anonfun$3, <function1>) at org.apache.spark.serializer.SerializationDebugger$.improveException(SerializationDebugger.scala:38) at org.apache.spark.serializer.JavaSerializationStream.writeObject(JavaSerializer.scala:47) at org.apache.spark.serializer.JavaSerializerInstance.serialize(JavaSerializer.scala:80) at org.apache.spark.util.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:164) ... 14 more 创建简单的应用程序。

我在声明MapView中心和缩放时遇到问题。我需要以编程方式(应用程序启动)在java文件中进行,而不是在xml文件中。我将尝试在简单的例子上解释它。

MapView我需要在mMapView.setMapOptions(options);中遇到问题,如果我使用onCreate() Button,一切正常。我在样本和互联网上搜索了解决方案,但我认为,我不知道如何询问它。

对不起我的英文,感谢您的评论。

mMapView.setMapOptions(options);

2 个答案:

答案 0 :(得分:0)

您可以从XML中删除MapView声明,并在活动中创建它。然后只需将MapView添加到您的布局中。

XML(详细信息省略)

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout android:id="@+id/mapLayout"></LinearLayout>

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
  MapView mapView = MapView(MainActivity.this, mapOpts);
  // other logic/initializations

  ViewGroup mapLayout = findViewById(R.id.mapLayout);
  mapLayout.addView(mapView); // might have to specify index param if you need buttons

答案 1 :(得分:0)

这是我之前的答案的解决方案。谢谢zec!

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.esri.android.map.MapOptions;
import com.esri.android.map.MapView;

public class MainActivity extends Activity {

    MapView mMapView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MapOptions options = new MapOptions(MapOptions.MapType.TOPO, 49.591241, 17.255503, 16);

        mMapView = new MapView(MainActivity.this, options);
        setContentView(mMapView);

    }

    @Override
    protected void onPause() {
        super.onPause();

        // Call MapView.pause to suspend map rendering while the activity is paused, which can save battery usage.
        mMapView.pause();
    }

    @Override
    protected void onResume() {
        super.onResume();

        // Call MapView.unpause to resume map rendering when the activity returns to the foreground.
       mMapView.unpause();
    }

}