0

SDK 'ArcGIS for Android' を使用して Android アプリを開発したいと考えています。そこから 2 つのサンプルをダウンロードしました: PopupInWebMapForViewing an Routing. それが私の目標です。これら 2 つのサンプルを 1 つの Projekt または 1 つの .java-File に入れたいのです。

完了しましたが、スマートフォンでアプリが動作しません。アプリが停止したことだけが表示されます。ルーティングからすべてのものをコメントアウトすると、機能します。また、ルーティングからレイヤー以外のすべてのコメントを外すと、それも機能します。ルーティングは、マップを長押しすると有効になります。ただし、この場合、アプリはクラッシュします。

私はJavaについてあまり知りませんが、大学のプロジェクトです。誰かが私を助けてくれることを願っています。

助けてくれてありがとう、そして私の下手な英語でごめんなさい。

コードは次のとおりです。

public class BAAppActivity extends Activity {

    // Progress dialog to show when route is being calculated
    ProgressDialog dialog;
    // Spatial references used for projecting points
    final SpatialReference wm = SpatialReference.create(102100);
    final SpatialReference egs = SpatialReference.create(4326);
    // Index of the currently selected route segment (-1 = no selection)
    int selectedSegmentID = -1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Lade die Basemap von ArcGIS online.
        map = new MapView(this, "map", "", "");
        setContentView(map);

        // Retrieve the map and initial extent from XML layout
        map = (MapView) findViewById(R.id.map);
        // Add tiled layer to MapView
        tileLayer = new ArcGISTiledMapServiceLayer(
                "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
        map.addLayer(tileLayer);

        // Add the route graphic layer (shows the full route)
        routeLayer = new GraphicsLayer();
        map.addLayer(routeLayer);

        // Add the hidden segments layer (for highlighting route segments)
        hiddenSegmentsLayer = new GraphicsLayer();
        map.addLayer(hiddenSegmentsLayer);

        // Make the segmentHider symbol "invisible"
        segmentHider.setAlpha(1);

        // Get the location service and start reading location. Don't auto-pan
        // to center our position
        LocationService ls = map.getLocationService();
        ls.setLocationListener(new MyLocationListener());
        ls.start();
        ls.setAutoPan(false);

        // Set the directionsLabel with initial instructions.
        directionsLabel = (TextView) findViewById(R.id.directionsLabel);
        directionsLabel.setText(getString(R.string.route_label));

        directionsLabel.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                if (curDirections == null)
                    return;
                Intent i = new Intent(getApplicationContext(),
                        ShowDirections.class);
                i.putStringArrayListExtra("directions", curDirections);
                startActivityForResult(i, 1);
            }

        });

        directionsLabel.setOnLongClickListener(new OnLongClickListener() {

            public boolean onLongClick(View v) {
                routeLayer.removeAll();
                hiddenSegmentsLayer.removeAll();
                curRoute = null;
                curDirections = null;
                directionsLabel.setText(getString(R.string.route_label));
                return true;
            }

        });

        // Tippe auf die Karte und öffne ein Popup für das selektierte Feature.
        map.setOnSingleTapListener(new OnSingleTapListener() {
            private static final long serialVersionUID = 1L;

            public void onSingleTap(float x, float y) {
                // Get all the graphics within 20 pixels the click
                int[] indexes = hiddenSegmentsLayer.getGraphicIDs(x, y, 20);
                // Hide the currently selected segment
                hiddenSegmentsLayer.updateGraphic(selectedSegmentID,
                        segmentHider);

                if (indexes.length < 1) {
                    // If no segments were found but there is currently a route,
                    // zoom to the extent of the full route
                    if (curRoute != null) {
                        map.setExtent(curRoute.getEnvelope(), 250);
                        directionsLabel.setText(routeSummary);
                    }
                    return;
                }
                // Otherwise update our currently selected segment
                selectedSegmentID = indexes[0];
                Graphic selected = hiddenSegmentsLayer
                        .getGraphic(selectedSegmentID);
                // Highlight it on the map
                hiddenSegmentsLayer.updateGraphic(selectedSegmentID,
                        segmentShower);
                String direction = ((String) selected.getAttributeValue("text"));
                double time = ((Double) selected.getAttributeValue("time"))
                        .doubleValue();
                double length = ((Double) selected.getAttributeValue("length"))
                        .doubleValue();
                // Update the label with this direction's information
                String label = String.format(
                        "%s%nTime: %.1f minutes, Length: %.1f miles",
                        direction, time, length);
                directionsLabel.setText(label);
                // Zoom to the extent of that segment
                map.setExtent(selected.getGeometry(), 50);

                if (map.isLoaded()) {
                    // PopupContainer realisieren.
                    popupContainer = new PopupContainer(map);
                    int id = popupContainer.hashCode();
                    popupDialog = null;
                    // spinner (Auswahl) anzeigen.
                    if (progressDialog == null || !progressDialog.isShowing())
                        progressDialog = ProgressDialog.show(map.getContext(), "", "Rufe Informationen ab...");

                    // Loop durch jeden Layer in der Basemap.
                    int tolerance = 20;
                        Envelope env = new Envelope(map.toMapPoint(x, y), 20 * map.getResolution(), 20 * map.getResolution());
                    Layer[] layers = map.getLayers();
                    count = new AtomicInteger();
                    for (Layer layer : layers) {
                        // Wenn der Layer noch nicht geladen wurde oder unsichtbar ist, nichts machen.
                        if (!layer.isInitialized() || !layer.isVisible())
                            continue;

                        if (layer instanceof ArcGISFeatureLayer) {
                            // Frage den FeatureLayer ab und zeige die Popups.
                            ArcGISFeatureLayer featureLayer = (ArcGISFeatureLayer) layer;
                            if (featureLayer.getPopupInfo() != null) {
                                // Frage den FeatureLayer ab, welcher mit den Popupdefinitionen verknüpft ist.
                                count.incrementAndGet();
                                new RunQueryFeatureLayerTask(x, y, tolerance, id).execute(featureLayer);
                            }
                        }
                        else if (layer instanceof ArcGISDynamicMapServiceLayer) {
                            // Frage den DynamicLayer ab und zeige die Popups.
                            ArcGISDynamicMapServiceLayer dynamicLayer = (ArcGISDynamicMapServiceLayer) layer;
                            // Empfange Layerinfos für jeden Sub-Layer des dynamic map service layer.
                            ArcGISLayerInfo[] layerinfos = dynamicLayer.getAllLayers();
                            if (layerinfos == null)
                                continue;

                            // Loop durch jeden Sub-Layer.
                            for (ArcGISLayerInfo layerInfo : layerinfos) {
                                // erhalte PopupInfo für die Sub-Layer.
                                PopupInfo popupInfo = dynamicLayer.getPopupInfo(layerInfo.getId());
                                // Überspringe Sub-Layer, welche keine Popup-Definitionen enthalten.
                                if (popupInfo == null) {
                                    continue;
                                }
                                // Überprüfe ob der Sub-Layer sichtbar ist.
                                ArcGISLayerInfo info = layerInfo;
                                while (info != null && info.isVisible()) {
                                    info = info.getParentLayer();
                                }
                                // Überspringe unsichtbare Sub-Layer.
                                if (info != null && ! info.isVisible()) {
                                    continue;
                                };

                                // Überprüfe ob der Sub-Layer innerhalb des Skalenbereichs ist.
                                double maxScale = (layerInfo.getMaxScale() != 0) ? layerInfo.getMaxScale():popupInfo.getMaxScale();
                                double minScale = (layerInfo.getMinScale() != 0) ? layerInfo.getMinScale():popupInfo.getMinScale();

                                if ((maxScale == 0 || map.getScale() > maxScale) && (minScale == 0 || map.getScale() < minScale)) {
                                    // Frage die Sub-Layer ab, welche mit den Popup-Definitionen verknüpft sind und sichtbar sind und im Skalenbereich liegen.
                                    count.incrementAndGet();
                                    new RunQueryDynamicLayerTask(env, layer, layerInfo.getId(), dynamicLayer.getSpatialReference(), id).execute(dynamicLayer.getUrl() + "/" + layerInfo.getId());
                                }
                            }
                        }               
                    }
                }
            }
        });

        map.setOnLongPressListener(new OnLongPressListener() {

            private static final long serialVersionUID = 1L;

            public void onLongPress(final float x, final float y) {

                // Clear the graphics and empty the directions list
                routeLayer.removeAll();
                hiddenSegmentsLayer.removeAll();
                curDirections = new ArrayList<String>();
                mResults = null;

                // retrieve the user clicked location
                final Point loc = map.toMapPoint(x, y);

                // Show that the route is calculating
                dialog = ProgressDialog.show(BAAppActivity.this, "",
                        "Calculating route...", true);
                // Spawn the request off in a new thread to keep UI responsive
                Thread t = new Thread() {
                    @Override
                    public void run() {
                        try {
                            // Start building up routing parameters
                            RoutingParameters rp = new RoutingParameters();
                            NAFeaturesAsFeature rfaf = new NAFeaturesAsFeature();
                            // Convert point to EGS (decimal degrees)
                            Point p = (Point) GeometryEngine.project(loc, wm,
                                    egs);
                            // Create the stop points (start at our location, go
                            // to pressed location)
                            StopGraphic point1 = new StopGraphic(mLocation);
                            StopGraphic point2 = new StopGraphic(p);
                            rfaf.setFeatures(new Graphic[] { point1, point2 });
                            rfaf.setCompressedRequest(true);
                            rp.setStops(rfaf);
                            // Set the routing service output SR to our map
                            // service's SR
                            rp.setOutSpatialReference(wm);

                            // Create a new routing task pointing to an
                            // NAService (null credentials -> free service)
                            RoutingTask rt = new RoutingTask(
                                    "http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_EU/NAServer/Route",
                                    null);

                            // Solve the route and use the results to update UI
                            // when received
                            mResults = rt.solve(rp);
                            mHandler.post(mUpdateResults);
                        } catch (Exception e) {
                            mException = e;
                            mHandler.post(mUpdateResults);
                        }
                    }
                };
                // Start the operation
                t.start();
            }
        });
    }

    private void createPopupViews(Graphic[] graphics, final int id) {
        if (id != popupContainer.hashCode()) {
            if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
                progressDialog.dismiss();

            return;
        }

        if (popupDialog == null) {
            if (progressDialog != null && progressDialog.isShowing())
                progressDialog.dismiss();

            // Mache einen Dialog für die popups und zeige ihn.
            popupDialog = new PopupDialog(map.getContext(), popupContainer);
            popupDialog.show();
        }
    }

    // Frage den Feature Layer durch einen Trefferüberprüfung ab.
    private class RunQueryFeatureLayerTask extends AsyncTask<ArcGISFeatureLayer, Void, Graphic[]> {

        private int tolerance;
        private float x;
        private float y;
        private ArcGISFeatureLayer featureLayer;
        private int id;

        public RunQueryFeatureLayerTask(float x, float y, int tolerance, int id) {
            super();
            this.x = x;
            this.y = y;
            this.tolerance = tolerance;
            this.id = id;
        }

        @Override
        protected Graphic [] doInBackground(ArcGISFeatureLayer...params) {
            for (ArcGISFeatureLayer featureLayer : params) {
                this.featureLayer = featureLayer;
                // Grafik-IDs in der Nähe der Punkte abrufen.
                int[] ids = featureLayer.getGraphicIDs(x, y, tolerance);
                if (ids != null && ids.length > 0) {
                    ArrayList<Graphic> graphics = new ArrayList<Graphic>();
                    for (int id : ids) {
                        // Grafiken basierend auf den IDs erhalten.
                        Graphic g = featureLayer.getGraphic(id);
                        if (g == null)
                            continue;
                        graphics.add(g);
                    }
                    // Liefert ein Array von Grafiken in der Nähe des Punktes.
                    return graphics.toArray(new Graphic[0]);
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Graphic[] graphics) {
            count.decrementAndGet();
            if (graphics == null || graphics.length == 0) {
                if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
                    progressDialog.dismiss();

                return;
            }

            for (Graphic gr : graphics) {
                Popup popup = featureLayer.createPopup(map, 0, gr);
                popupContainer.addPopup(popup);
            }
            createPopupViews(graphics, id);
        }

    }

    // Frage den Dynamic Map Service Layer mit QueryTask ab.
    private class RunQueryDynamicLayerTask extends AsyncTask<String, Void, FeatureSet> {
        private Envelope env;
        private SpatialReference sr;
        private int id;
        private Layer layer;
        private int subLayerId;

        public RunQueryDynamicLayerTask(Envelope env, Layer layer, int subLayerId, SpatialReference sr, int id) {
            super();
            this.env = env;
            this.sr = sr;
            this.id = id;
            this.layer = layer;
            this.subLayerId = subLayerId;
        }

        @Override
        protected FeatureSet doInBackground(String... urls) {
            for (String url : urls) {
                // Erhalte Grafiken innerhalb der Hülle.
                Query query = new Query();
                query.setInSpatialReference(sr);
                query.setOutSpatialReference(sr);
                query.setGeometry(env);
                query.setMaxFeatures(10);
                query.setOutFields(new String[] { "*" });

                QueryTask queryTask = new QueryTask(url);
                try {
                    FeatureSet results = queryTask.execute(query);
                    return results;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(final FeatureSet result) {
            count.decrementAndGet();
            if (result == null) {
                if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
                    progressDialog.dismiss();

                return;
            }
            Graphic[] graphics = result.getGraphics();
            if (graphics == null || graphics.length == 0) {
                if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
                    progressDialog.dismiss();

                return;
            }
            // Überprüfen, ob die angeforderte PopupContainer-Id identisch mit dem aktuellen PopupContainer ist.
            // Andernfalls verlasse die veralteten Abfragen.
            if (id != popupContainer.hashCode()) {
                // Spinner verwerfen.
                if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
                    progressDialog.dismiss();

                return;
            }
            PopupInfo popupInfo = layer.getPopupInfo(subLayerId);
            if (popupInfo == null) {
                // Spinner verwerfen.
                if (progressDialog != null && progressDialog.isShowing() && count.intValue() == 0)
                    progressDialog.dismiss();

                return;
            }

            for (Graphic gr : graphics) {
                Popup popup = layer.createPopup(map,  subLayerId,  gr);
                popupContainer.addPopup(popup);

            }
            createPopupViews(graphics, id);

        }
    }

    // Ein angepasster Vollbild-Dialog.
    private class PopupDialog extends Dialog {
        private PopupContainer popupContainer;

        public PopupDialog(Context context, PopupContainer popupContainer) {
            super(context, android.R.style.Theme);
            this.popupContainer = popupContainer;           
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                LinearLayout layout = new LinearLayout(getContext());
                layout.addView(popupContainer.getPopupContainerView(), LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
                setContentView(layout, params);
        }

    }

    void updateUI() {
        dialog.dismiss();
        if (mResults == null) {
            Toast.makeText(BAAppActivity.this, mException.toString(),
                    Toast.LENGTH_LONG).show();
            return;
        }
        curRoute = mResults.getRoutes().get(0);
        // Symbols for the route and the destination (blue line, checker flag)
        SimpleLineSymbol routeSymbol = new SimpleLineSymbol(Color.BLUE, 3);
        PictureMarkerSymbol destinationSymbol = new PictureMarkerSymbol(
                getResources().getDrawable(R.drawable.flag_finish));

        // Add all the route segments with their relevant information to the
        // hiddenSegmentsLayer, and add the direction information to the list
        // of directions
        for (RoutingDirection rd : curRoute.getRoutingDirections()) {
            HashMap<String, Object> attribs = new HashMap<String, Object>();
            attribs.put("text", rd.getText());
            attribs.put("time", Double.valueOf(rd.getTime()));
            attribs.put("length", Double.valueOf(rd.getLength()));
            curDirections.add(String.format(
                    "%s%nTime: %.1f minutes, Length: %.1f miles", rd.getText(),
                    rd.getTime(), rd.getLength()));
            hiddenSegmentsLayer.addGraphic(new Graphic(rd.getGeometry(),
                    segmentHider, attribs, null));
        }
        // Reset the selected segment
        selectedSegmentID = -1;

        // Add the full route graphic and destination graphic to the routeLayer
        Graphic routeGraphic = new Graphic(curRoute.getRoute().getGeometry(),
                routeSymbol);
        Graphic endGraphic = new Graphic(
                ((Polyline) routeGraphic.getGeometry()).getPoint(((Polyline) routeGraphic
                        .getGeometry()).getPointCount() - 1), destinationSymbol);
        routeLayer.addGraphics(new Graphic[] { routeGraphic, endGraphic });
        // Get the full route summary and set it as our current label
        routeSummary = String.format(
                "%s%nTotal time: %.1f minutes, length: %.1f miles",
                curRoute.getRouteName(), curRoute.getTotalTime(),
                curRoute.getTotalLength());
        directionsLabel.setText(routeSummary);
        // Zoom to the extent of the entire route with a padding
        map.setExtent(curRoute.getEnvelope(), 250);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // Response from directions list view
        if (requestCode == 1) {
            if (resultCode == RESULT_OK) {
                String direction = data.getStringExtra("returnedDirection");
                if (direction == null)
                    return;
                // Look for the graphic that corresponds to this direction
                for (int index : hiddenSegmentsLayer.getGraphicIDs()) {
                    Graphic g = hiddenSegmentsLayer.getGraphic(index);
                    if (direction
                            .contains((String) g.getAttributeValue("text"))) {
                        // When found, hide the currently selected, show the new
                        // selection
                        hiddenSegmentsLayer.updateGraphic(selectedSegmentID,
                                segmentHider);
                        hiddenSegmentsLayer.updateGraphic(index, segmentShower);
                        selectedSegmentID = index;
                        // Update label with information for that direction
                        directionsLabel.setText(direction);
                        // Zoom to the extent of that segment
                        map.setExtent(
                                hiddenSegmentsLayer.getGraphic(
                                        selectedSegmentID).getGeometry(), 50);
                        break;
                    }
                }
            }
        }
    }

    private class MyLocationListener implements LocationListener {

        public MyLocationListener() {
            super();
        }

        /**
         * If location changes, update our current location. If being found for
         * the first time, zoom to our current position with a resolution of 20
         */
        public void onLocationChanged(Location loc) {
            if (loc == null)
                return;
            boolean zoomToMe = (mLocation == null) ? true : false;
            mLocation = new Point(loc.getLongitude(), loc.getLatitude());
            if (zoomToMe) {
                Point p = (Point) GeometryEngine.project(mLocation, egs, wm);
                map.zoomToResolution(p, 20.0);
            }
        }    
    }
}

そしてLogCat:

10-28 14:19:27.586: E/ArcGIS(26937): Can not parse MapView.initExtent from xml
10-28 14:19:27.586: E/ArcGIS(26937): java.text.ParseException: Unparseable number: "-19332033.11," (at offset 9)
10-28 14:19:27.586: E/ArcGIS(26937):    at java.text.NumberFormat.parse(NumberFormat.java:545)
10-28 14:19:27.586: E/ArcGIS(26937):    at com.esri.android.map.MapView.a(Unknown Source)
10-28 14:19:27.586: E/ArcGIS(26937):    at com.esri.android.map.MapView.a(Unknown Source)
10-28 14:19:27.586: E/ArcGIS(26937):    at com.esri.android.map.MapView.<init>(Unknown Source)
10-28 14:19:27.586: E/ArcGIS(26937):    at java.lang.reflect.Constructor.constructNative(Native Method)
10-28 14:19:27.586: E/ArcGIS(26937):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-28 14:19:27.586: E/ArcGIS(26937):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:318)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.app.Activity.setContentView(Activity.java:1901)
10-28 14:19:27.586: E/ArcGIS(26937):    at fhffm.wernicke.ba.app.BAAppActivity.onCreate(BAAppActivity.java:111)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.app.Activity.performCreate(Activity.java:5047)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.app.ActivityThread.access$700(ActivityThread.java:134)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.os.Looper.loop(Looper.java:137)
10-28 14:19:27.586: E/ArcGIS(26937):    at android.app.ActivityThread.main(ActivityThread.java:4867)
10-28 14:19:27.586: E/ArcGIS(26937):    at java.lang.reflect.Method.invokeNative(Native Method)
10-28 14:19:27.586: E/ArcGIS(26937):    at java.lang.reflect.Method.invoke(Method.java:511)
10-28 14:19:27.586: E/ArcGIS(26937):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
10-28 14:19:27.586: E/ArcGIS(26937):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
10-28 14:19:27.586: E/ArcGIS(26937):    at dalvik.system.NativeStart.main(Native Method)
10-28 14:19:27.806: E/SensorManager(26937): thread start
10-28 14:19:27.816: E/AndroidRuntime(26937): FATAL EXCEPTION: main
10-28 14:19:27.816: E/AndroidRuntime(26937): java.lang.RuntimeException: Unable to start activity ComponentInfo{fhffm.wernicke.ba.app/fhffm.wernicke.ba.app.BAAppActivity}: java.lang.NullPointerException
10-28 14:19:27.816: E/AndroidRuntime(26937):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at android.app.ActivityThread.access$700(ActivityThread.java:134)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at android.os.Looper.loop(Looper.java:137)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at android.app.ActivityThread.main(ActivityThread.java:4867)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at java.lang.reflect.Method.invokeNative(Native Method)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at java.lang.reflect.Method.invoke(Method.java:511)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at dalvik.system.NativeStart.main(Native Method)
10-28 14:19:27.816: E/AndroidRuntime(26937): Caused by: java.lang.NullPointerException
10-28 14:19:27.816: E/AndroidRuntime(26937):    at fhffm.wernicke.ba.app.BAAppActivity.onCreate(BAAppActivity.java:146)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at android.app.Activity.performCreate(Activity.java:5047)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
10-28 14:19:27.816: E/AndroidRuntime(26937):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
10-28 14:19:27.816: E/AndroidRuntime(26937):    ... 11 more

よろしくロサルカ

4

2 に答える 2

0

Routing サンプルで、res/layout/main.xml を見てください。MapView は、次の XML で宣言されます。

<com.esri.android.map.MapView
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    initExtent = "-19332033.11, -3516.27, -1720941.80, 11737211.28">
</com.esri.android.map.MapView>

残念ながら、initExtent の形式が正しくありません。コンマではなく、スペースのみを含める必要があります。

    initExtent = "-19332033.11 -3516.27 -1720941.80 11737211.28">

コンマを削除して、試してみてください。

于 2013-10-29T17:20:19.813 に答える
0

私は自分でそれを解決しました:

これを削除します:

map = new MapView(this, "some map", "", "");
setContentView(map);

そしてこれを追加します:

featureLayer = new ArcGISFeatureLayer(
                "featureLayer", MODE.ONDEMAND);
map.addLayer(featureLayer);

後:

map = (MapView) findViewById(R.id.map);
tileLayer = new ArcGISTiledMapServiceLayer(
                 "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
map.addLayer(tileLayer);

しかし、私には新しい問題があります: 機能をタブで検索したい場合、検索に時間がかかり、何も表示されません。ルート概要をタップすると、アプリがクラッシュします。2つの「onSingleTab」メソッドが原因でクラッシュすると思います。これを 2 つの異なる目的で 2 つ作成するにはどうすればよいですか (「onSingleTab1」で「Routing」をテストしました...)。このコードには、機能も含まれています。ループがレイヤーを検索するため、表示されないと思います。しかし、私が持っている唯一のレイヤーは、機能を備えた機能レイヤーです。知らない...

map.setOnSingleTapListener(new OnSingleTapListener() {
            private static final long serialVersionUID = 1L;

            public void onSingleTap(float x, float y) {
                if (map.isLoaded()) {
                    // PopupContainer realisieren.
                    popupContainer = new PopupContainer(map);
                    int id = popupContainer.hashCode();
                    popupDialog = null;
                    // spinner (Auswahl) anzeigen.
                    if (progressDialog == null || !progressDialog.isShowing())
                        progressDialog = ProgressDialog.show(map.getContext(), "", "Rufe Informationen ab...");

                    // Loop durch jeden Layer in der Basemap.
                    int tolerance = 20;
                        Envelope env = new Envelope(map.toMapPoint(x, y), 20 * map.getResolution(), 20 * map.getResolution());
                    Layer[] layers = map.getLayers();
                    count = new AtomicInteger();
                    for (Layer layer : layers) {
                        // Wenn der Layer noch nicht geladen wurde oder unsichtbar ist, nichts machen.
                        if (!layer.isInitialized() || !layer.isVisible())
                            continue;

                        if (layer instanceof ArcGISFeatureLayer) {
                            // Frage den FeatureLayer ab und zeige die Popups.
                            ArcGISFeatureLayer featureLayer = (ArcGISFeatureLayer) layer;
                            if (featureLayer.getPopupInfo() != null) {
                                // Frage den FeatureLayer ab, welcher mit den Popupdefinitionen verknüpft ist.
                                count.incrementAndGet();
                                new RunQueryFeatureLayerTask(x, y, tolerance, id).execute(featureLayer);
                            }
                        }
                    }
                }
            }
            ////////////////////////////// Routing /////////////////////////////
            public void onSingleTap1(float x, float y) {
            // Get all the graphics within 20 pixels the click
            int[] indexes = hiddenSegmentsLayer.getGraphicIDs(x, y, 20);
            // Hide the currently selected segment
            hiddenSegmentsLayer.updateGraphic(selectedSegmentID,
                    segmentHider);

            if (indexes.length < 1) {
                // If no segments were found but there is currently a route,
                // zoom to the extent of the full route
                if (curRoute != null) {
                    map.setExtent(curRoute.getEnvelope(), 250);
                    directionsLabel.setText(routeSummary);
                }
                return;
            }
            // Otherwise update our currently selected segment
            selectedSegmentID = indexes[0];
            Graphic selected = hiddenSegmentsLayer
                    .getGraphic(selectedSegmentID);
            // Highlight it on the map
            hiddenSegmentsLayer.updateGraphic(selectedSegmentID,
                    segmentShower);
            String direction = ((String) selected.getAttributeValue("text"));
            double time = ((Double) selected.getAttributeValue("time"))
                    .doubleValue();
            double length = ((Double) selected.getAttributeValue("length"))
                    .doubleValue();
            // Update the label with this direction's information
            String label = String.format(
                    "%s%nTime: %.1f minutes, Length: %.1f miles",
                    direction, time, length);
            directionsLabel.setText(label);
            // Zoom to the extent of that segment
            map.setExtent(selected.getGeometry(), 50);
            }
        });

よろしくお願いします

ロサルカ

于 2013-10-30T15:22:43.813 に答える