【问题标题】:MapView ist abstract - cannot be instantiatedMapView ist abstract - 无法实例化
【发布时间】:2019-09-02 19:22:51
【问题描述】:

我实际上是在尝试在使用 Android Studio 构建的应用中显示地图。 我使用图书馆“mapsforge”(https://github.com/mapsforge) 在创建地图视图实例时出现错误。

我集成了以下库:

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'org.mapsforge:mapsforge-core:[0.11.0]'
implementation 'org.mapsforge:mapsforge-map:[0.11.0]'
implementation 'org.mapsforge:mapsforge-map-reader:[0.11.0]'
implementation 'org.mapsforge:mapsforge-themes:[0.11.0]'
implementation 'net.sf.kxml:kxml2:2.3.0'

在 MainActivity 中:

import org.mapsforge.map.view.MapView;

我的整个 OnCreate:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    AndroidGraphicFactory.createInstance(getApplication());
    mapView = new MapView(this);

    mapView.setClickable(true);
    mapView.getMapScaleBar().setVisible(false);
    mapView.setBuiltInZoomControls(false);
    mapView.setZoomLevelMin((byte) 2);
    mapView.setZoomLevelMax((byte) 10);

    mapView.setZoomLevel((byte) 2);
      mapView.getModel().displayModel.setBackgroundColor(ContextCompat.getColor(t his, R.color.mapBackground));
}
}

投掷:
MapView 是抽象的 - 无法实例化。

Java 中的新人

提前致谢

【问题讨论】:

  • 他们在示例代码中使用了不同的导入:import org.mapsforge.map.android.view.MapView;
  • 感谢您的帮助!但它只是说:“未使用的导入语句”和“android”是红色标记的。

标签: java android android-studio mapsforge


【解决方案1】:

要在 Android 中使用 MapView,您需要将 Android 实现添加到您的 gradle 依赖项中:

implementation 'org.mapsforge:mapsforge-map-android:[CURRENT-VERSION]'
implementation 'com.caverock:androidsvg:1.4'

查看其存储库中的集成指南:https://github.com/mapsforge/mapsforge/blob/master/docs/Integration.md

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 2016-06-09
    • 2020-10-26
    • 2016-11-22
    • 2016-02-29
    相关资源
    最近更新 更多