Android应用程序因NullPointerException而崩溃

时间:2014-08-07 10:36:16

标签: java android google-maps

我在应用程序上有一些奇怪的崩溃,但我暂时无法重现它。这是日志:

java.lang.NullPointerException
   at oup.a()
   at oup.a()
   at oyf.a()
   at grl.onTransact(SourceFile:167)
   at android.os.Binder.transact(Binder.java:347)
   at com.google.android.gms.maps.internal.IGoogleMapDelegate$a$a.getCameraPosition()
   at com.google.android.gms.maps.GoogleMap.getCameraPosition()
   at com.Parkable.showDetail(Parkable.java:220)
   at com.MapActivity.updateMap$1385ff(MapActivity.java:1496)
   at com.Parkable$Collection.onFetchCompletion(Parkable.java:731)
   at com.Facility$Collection$1.onFinish(Facility.java:859)
   at com.Facility$FetchTask.onPostExecute(Facility.java:825)
   at com.Facility$FetchTask.onPostExecute(Facility.java:597)
   at android.os.AsyncTask.finish(AsyncTask.java:631)
   at android.os.AsyncTask.access$600(AsyncTask.java:177)
   at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:5455)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:525)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
   at dalvik.system.NativeStart.main(NativeStart.java)

Parkable 220 line

mapMarker = mapActivity.map.addMarker(options);

两种方法:

public void showDot(MapActivity mapActivity, Parkable parking) {
    if (mapMarker != null)
        throw new AssertionError("Marker already shown!");

    String snippet = "";

    if (ccAccepted())
        snippet = mapActivity.getString(R.string.cc_accepted);

    if (haveOccupancy)
        snippet += " • " + getOccupancyText();

    MarkerOptions options = new MarkerOptions();
    options.position(pos);
    options.title(getTitle());
    options.snippet(snippet);
    options.icon(getDotBitmapDescriptor(mapActivity, parking instanceof Facility));
    mapMarker = mapActivity.map.addMarker(options);
    visibleMarkers.put(mapMarker.getId(), this);
    dotShown = true;
}
public BitmapDescriptor getDotBitmapDescriptor(Activity context, final boolean isFacilityParking) {
    if (USE_RATE_COLOR_SCHEME && isFacilityParking) {
        return BitmapDescriptorFactory.fromBitmap(generateDot(context));
    }
    if (bitmapDescriptor != null)
        return bitmapDescriptor;

    String key = getMarkerId();

    bitmapDescriptor = bitmapDescriptorCache.get(key);
    if (bitmapDescriptor == null) {
        bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(generateDot(context));
        bitmapDescriptorCache.put(key, bitmapDescriptor);
    }

    return bitmapDescriptor;
}

地图片段是

public class MapFragmentWithTouch extends MapFragment {

private static final String TAG = "SupportFragmentWithTouch";
private View originalContentView;
private GoogleMap map;
private MapMovementListener movementListener;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    originalContentView = super.onCreateView(inflater, parent, savedInstanceState);
    TouchableWrapper touchView = new TouchableWrapper(getActivity());
    touchView.addView(originalContentView);
    map = getMap();

    return touchView;
}

@Override
public View getView() {
    return originalContentView;
}

public void setMapMovementListener(MapMovementListener movementListener) {
    this.movementListener = movementListener;
}

public void clearMapMovementListener() {
    this.movementListener = null;
}

public interface MapMovementListener {
    public void onMapMove(LatLng center);

    public void onMoveStart();

    public void onMoveStop();
}

private class TouchableWrapper extends FrameLayout {
    private boolean isMoving;

    public TouchableWrapper(Context context) {
        super(context);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (map == null)
            return super.dispatchTouchEvent(ev);

        LatLng center = map.getCameraPosition().target;

        if (movementListener != null) {
            movementListener.onMapMove(center);

            final int action = ev.getAction();
            switch (action & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_MOVE:
                if (!isMoving)
                    movementListener.onMoveStart();

                isMoving = true;
                break;

            case MotionEvent.ACTION_UP:
                if (isMoving)
                    movementListener.onMoveStop();

                isMoving = false;
                break;
            }
        }

        return super.dispatchTouchEvent(ev);
    }
}

}

OnResume中的init map的主要活动方法中:

private void setUpMapIfNeeded() {
    if (map != null)
        return;
    // Try to obtain the map from the MapFragment
    map = ((MapFragmentWithTouch)getFragmentManager().findFragmentById(R.id.map)).getMap();
    if (map != null)
        setUpMap();
}

有人有这种情况吗?感谢任何帮助。

0 个答案:

没有答案