尝试调用另一个onGestureListener Adapter()时应用程序崩溃

问题描述 投票:-1回答:1

我创建了2个onTapEvent监听器,通过单击不同的按钮将不同图标的标记添加到我的地图中。但是,我只能添加1种类型的标记,第二个按钮(添加人群)会在我点击它之后崩溃我的应用程序。

以下是我的按钮代码示例:

设定目的地:

private void initAddDestinationButton() {
m_setDetinationButton = (Button) findViewById(R.id.setDestinationButton);

m_setDetinationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
             /*
             * Clear map if previous results are still on map,otherwise proceed to creating
             * route
             */
            if (map != null && m_mapRoute != null) {
                map.removeMapObject(m_mapRoute);
                m_mapRoute = null;
            } else
            {
                 addDestination();
            }
        }
    });
}

private void addDestination() {
    if (destinationMarker == null) {
        image = new Image();
        try {
            image.setImageResource(R.drawable.letterx);
        } catch (final IOException e) {
            e.printStackTrace();
        }
    }
    mapFragment.getMapGesture().removeOnGestureListener(addCrowdListener2);
    mapFragment.getMapGesture().addOnGestureListener(setDestinationListener2, 1, true);

}

添加人群:

private void initAddCrowdButton() {
m_addCrowdButton = (Button) findViewById(R.id.addCrowdButton);

m_addCrowdButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view2) {

            if (map != null && m_mapRoute != null) {
                map.removeMapObject(m_mapRoute);
                m_mapRoute = null;
            } else
            {
                addCrowd();

            }
        }
    });

}


private void addCrowd() {
    if (blocked == null) {
        image2 = new Image();
        try {
            image.setImageResource(R.drawable.marker);
        } catch (final IOException e) {
            e.printStackTrace();
        }
    }
    mapFragment.getMapGesture().removeOnGestureListener(setDestinationListener2);
    mapFragment.getMapGesture().addOnGestureListener(addCrowdListener2, 10, true);

}

以下是我声明的2个onTapEvent侦听器:

private MapGesture.OnGestureListener addCrowdListener2 = new MapGesture.OnGestureListener.OnGestureListenerAdapter() {
    @Override
    public boolean onTapEvent(PointF pointF) {

        GeoCoordinate e = map.pixelToGeo(pointF);
        MapMarker b = new MapMarker(e, image2);

        blockList.add(b);
        b.setAnchorPoint(new PointF(image.getWidth()/2, image.getHeight()));
        map.addMapObject(b);

        blocked = blockList.get(blockList.size() - 1);
        blockedPath = blocked.getCoordinate();
        blockedRoad = RoadElement.getRoadElement(blockedPath, "eng" );

        return super.onTapEvent(pointF);
    }
};

private MapGesture.OnGestureListener setDestinationListener2 = new MapGesture.OnGestureListener.OnGestureListenerAdapter() {
    @Override
    public boolean onTapEvent(PointF pointF) {
        GeoCoordinate endpoint = map.pixelToGeo(pointF);

            MapMarker m = new MapMarker(endpoint,image);

            markerList.add(m);
            m.setAnchorPoint(new PointF(image.getWidth()/2, image.getHeight()));
            map.addMapObject(m);

            destinationMarker = markerList.get(markerList.size() - 1);

            destination = destinationMarker.getCoordinate();

        return super.onTapEvent(pointF);
    }
};

我已经在OnEngineInitiaizatioCompleted()内宣布了按钮。到目前为止,只有Set Destination按钮正常运行。单击Add Crowd将使我的应用程序崩溃(在单击Set Destination之前和之后单击它,单击时崩溃应用程序)

这是崩溃的堆栈跟踪:

02-26 22:22:33.907 2233-3776/com.google.android.googlequicksearchbox:search W/ErrorProcessor: onFatalError, processing error from engine(4)
                                                                                          com.google.android.apps.gsa.shared.speech.a.g: Error reading from input stream
                                                                                              at com.google.android.apps.gsa.staticplugins.recognizer.i.a.a(SourceFile:342)
                                                                                              at com.google.android.apps.gsa.staticplugins.recognizer.i.a$1.run(SourceFile:1367)
                                                                                              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
                                                                                              at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                              at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:66)
                                                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                                              at java.lang.Thread.run(Thread.java:761)
                                                                                              at com.google.android.apps.gsa.shared.util.concurrent.a.ad$1.run(SourceFile:85)
                                                                                           Caused by: com.google.android.apps.gsa.shared.exception.GsaIOException: Error code: 393238 | Buffer overflow, no available space.
                                                                                              at com.google.android.apps.gsa.speech.audio.Tee.g(SourceFile:2531)
                                                                                              at com.google.android.apps.gsa.speech.audio.ap.read(SourceFile:555)
                                                                                              at java.io.InputStream.read(InputStream.java:101)
                                                                                              at com.google.android.apps.gsa.speech.audio.al.run(SourceFile:362)
                                                                                              at com.google.android.apps.gsa.speech.audio.ak$1.run(SourceFile:471)
                                                                                              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
                                                                                              at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                              at com.google.android.apps.gsa.shared.util.concurrent.a.ak.run(SourceFile:66)
                                                                                              at com.google.android.apps.gsa.shared.util.concurrent.a.ax.run(SourceFile:139)
                                                                                              at com.google.android.apps.gsa.shared.util.concurrent.a.ax.run(SourceFile:139)
                                                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
                                                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
                                                                                              at java.lang.Thread.run(Thread.java:761) 
                                                                                              at com.google.android.apps.gsa.shared.util.concurrent.a.ad$1.run(SourceFile:85) 

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.here.android.mpa.common.Image.setImageResource(int)' on a null object reference
at com.here.android.example.basicpositioningsolution.BasicPositioningActivity.addCrowd(BasicPositioningActivity.java:532)
at com.here.android.example.basicpositioningsolution.BasicPositioningActivity.access$1600(BasicPositioningActivity.java:87)
at com.here.android.example.basicpositioningsolution.BasicPositioningActivity$7.onClick(BasicPositioningActivity.java:521)
at android.view.View.performClick(View.java:5619)
at android.view.View$PerformClick.run(View.java:22295)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6342)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
Suppressed: java.lang.Throwable: HERE SDK Version: 3.6.0.523
    at com.nokia.maps.MapsEngine$l.uncaughtException(MapsEngine.java:377)
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
    at java.lang.Thread.dispatchUncaughtException(Thread.java:1979)
java android here-api
1个回答
0
投票

我认为您的资源R.drawable.marker无法由SDK呈现。它是什么样的图像资源?仅支持位图资源。

© www.soinside.com 2019 - 2024. All rights reserved.