1

I'm trying to use ArcGIS to draw some shape file on the map using its ShapefileFeatureTable. But when I try the load the shape file I get a File not found Exception.
This is the code I'm using:

ShapefileFeatureTable shapefileFeatureTable;
try {
    shapefileFeatureTable = new ShapefileFeatureTable(Environment.getExternalStorageDirectory().getAbsolutePath() + "/shape.shp");
} catch (Exception e) {
    e.printStackTrace();
    Toast.makeText(this, "loading shape failed", Toast.LENGTH_SHORT).show();
    return;
}

The catch here is that the shape file actually exists on the sdcard. I debugged the code and reached this part which is throwing the exception:

static Geodatabase a(String var0) throws FileNotFoundException {
    File var1 = new File(var0);
    if(!var1.exists()) {
        throw new FileNotFoundException(var1 + " does not exist.");
    } else {
        return new Geodatabase(nativeOpenShapefile(var0)); // this is where it happens
    }
}

The native nativeOpenShapefile seems to not be able to see the file while the java part perfectly sees it. Check the stacktrace:

D/dalvikvm: Trying to load lib /data/data/com.hmomeni.arcgis/lib/libruntimecore_java.so 0x4163daf0 D/dalvikvm: Added shared lib /data/data/com.hmomeni.arcgis/lib/libruntimecore_java.so 0x4163daf0 W/System.err: java.lang.RuntimeException: Shape file not found: /storage/sdcard0/shape.shp W/System.err: at com.esri.core.geodatabase.Geodatabase.nativeOpenShapefile(Native Method) W/System.err: at com.esri.core.geodatabase.Geodatabase.a(SourceFile:126) W/System.err: at com.esri.core.geodatabase.ShapefileFeatureTable.(SourceFile:79) W/System.err: at com.hmomeni.arcgis.MainActivity.initView(MainActivity.java:32) W/System.err: at com.hmomeni.arcgis.MainActivity.onCreate(MainActivity.java:21) W/System.err: at android.app.Activity.performCreate(Activity.java:5031) W/System.err:
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082) W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2038) W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2099) W/System.err: at android.app.ActivityThread.access$600(ActivityThread.java:134) W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207) W/System.err: at android.os.Handler.dispatchMessage(Handler.java:99) W/System.err:
at android.os.Looper.loop(Looper.java:137) W/System.err: at android.app.ActivityThread.main(ActivityThread.java:4797) W/System.err: at java.lang.reflect.Method.invokeNative(Native Method) W/System.err: at java.lang.reflect.Method.invoke(Method.java:511) W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:776) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:543) W/System.err: at dalvik.system.NativeStart.main(Native Method)

I wonder what could be the problem?

4

2 回答 2

1

在 AndroidManifest.xml 中,您是否请求了读取和/或写入外部存储的权限?

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

或者

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

尝试其中的每一个,看看是否有帮助。有关详细信息,请参阅ArcGIS Runtime 文档并阅读“所需权限和功能”部分。

于 2016-12-21T14:56:32.980 回答
1

问题原来是我没有包含文件附带的所有必要.shp文件。为此目的还需要其他文件,例如.shx, .dbf, .prj.
包括他们都解决了这个问题。

于 2017-01-05T06:15:36.020 回答