Java 尝试调用另一个OnTestureListenerAdapter()时应用程序崩溃
我创建了2个Java 尝试调用另一个OnTestureListenerAdapter()时应用程序崩溃,java,android,here-api,Java,Android,Here Api,我创建了2个onTapEventlistener,通过单击不同的按钮将不同图标的标记添加到我的地图中。但是,我只能添加1种标记,第二个按钮(添加群组)将在我单击后使我的应用程序崩溃 下面是我的按钮代码示例: 设置目的地: private void initAddDestinationButton() { m_setDetinationButton = (Button) findViewById(R.id.setDestinationButton); m_setDetinationButton.
onTapEvent
listener,通过单击不同的按钮将不同图标的标记添加到我的地图中。但是,我只能添加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);
}
下面是我声明的两个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);
}
};
我已经声明了onengineinitiazatioCompleted()
中的按钮。到目前为止,只有设置目的地按钮正常运行。单击“添加群组”将使我的应用程序崩溃(在单击“设置目的地”之前和之后单击它,在单击时使应用程序崩溃)
以下是其崩溃的堆栈跟踪:
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)
及
我认为SDK无法呈现您的资源R.drawable.marker。它是什么样的图像资源?仅支持位图资源。应用程序崩溃?我们也会发布堆栈跟踪。嗨@ADM,我已经添加了堆栈跟踪。
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)