Android Studio 应用程序在触摸 MapView 时崩溃

Posted

技术标签:

【中文标题】Android Studio 应用程序在触摸 MapView 时崩溃【英文标题】:Android Studio Application Crashing on touching MapView 【发布时间】:2022-01-14 14:21:57 【问题描述】:

当我触摸、滚动或与 Mapbox Mapview 交互时,我遇到了这个奇怪的错误。我真的不明白错误消息,如果有人能提供一些见解,我很感激我尝试了一切......

你应该知道,我不是在一个活动中调用地图视图,而是在一个对话框中显示它,这是代码:

newReservation.setPickup_date(datePicker.getYear() + "/" + (datePicker.getMonth()+1)  + "/" + datePicker.getDayOfMonth() + " " + timePicker.getHour() + ":" + timePicker.getMinute());
dialog.setContentView(R.layout.enddatedialog);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
DatePicker datePicker;
TimePicker timePicker;
ImageView imageViewClose = dialog.findViewById(R.id.dialogClose);
Button continueBtn = dialog.findViewById(R.id.dialogContinueBtn);

datePicker = dialog.findViewById(R.id.dialogEndDate);
timePicker = dialog.findViewById(R.id.dialogEndTime);

imageViewClose.setOnClickListener(new View.OnClickListener() 
    @Override
    public void onClick(View v) 
        dialog.dismiss();
    
);

continueBtn.setOnClickListener(new View.OnClickListener() 
    @Override
    public void onClick(View v) 
        dialog.dismiss();
        newReservation.setDropoff_date(datePicker.getYear() + "/" + (datePicker.getMonth()+1)  + "/" + datePicker.getDayOfMonth() + " " + timePicker.getHour() + ":" + timePicker.getMinute());
        dialog.setContentView(R.layout.startlocationdialog);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        mapView = dialog.findViewById(R.id.dialogMap);
    
);

错误信息:

E/androidRuntime: FATAL EXCEPTION: main
    Process: com.example.project, PID: 4209
    java.lang.SecurityException: getDataNetworkTypeForSubscriber
        at android.os.Parcel.createExceptionOrNull(Parcel.java:2373)
        at android.os.Parcel.createException(Parcel.java:2357)
        at android.os.Parcel.readException(Parcel.java:2340)
        at android.os.Parcel.readException(Parcel.java:2282)
        at com.android.internal.telephony.ITelephony$Stub$Proxy.getNetworkTypeForSubscriber(ITelephony.java:8762)
        at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:3021)
        at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2985)
        at com.mapbox.android.telemetry.TelemetryUtils.obtainCellularNetworkType(TelemetryUtils.java:148)
        at com.mapbox.android.telemetry.MapClickEvent.<init>(MapClickEvent.java:45)
        at com.mapbox.android.telemetry.MapEventFactory.buildMapClickEvent(MapEventFactory.java:65)
        at com.mapbox.android.telemetry.MapEventFactory.access$000(MapEventFactory.java:15)
        at com.mapbox.android.telemetry.MapEventFactory$2$1.build(MapEventFactory.java:36)
        at com.mapbox.android.telemetry.MapEventFactory.createMapGestureEvent(MapEventFactory.java:61)
        at com.mapbox.mapboxsdk.maps.MapGestureDetector.sendTelemetryEvent(MapGestureDetector.java:893)
        at com.mapbox.mapboxsdk.maps.MapGestureDetector.access$700(MapGestureDetector.java:42)
        at com.mapbox.mapboxsdk.maps.MapGestureDetector$MoveGestureListener.onMoveBegin(MapGestureDetector.java:442)
        at com.mapbox.android.gestures.MoveGestureDetector.analyzeMovement(MoveGestureDetector.java:154)
        at com.mapbox.android.gestures.MultiFingerGesture.analyzeEvent(MultiFingerGesture.java:98)
        at com.mapbox.android.gestures.ProgressiveGesture.analyzeEvent(ProgressiveGesture.java:46)
        at com.mapbox.android.gestures.MoveGestureDetector.analyzeEvent(MoveGestureDetector.java:135)
        at com.mapbox.android.gestures.BaseGesture.analyze(BaseGesture.java:56)
        at com.mapbox.android.gestures.BaseGesture.onTouchEvent(BaseGesture.java:34)
        at com.mapbox.android.gestures.AndroidGesturesManager.onTouchEvent(AndroidGesturesManager.java:186)
        at com.mapbox.mapboxsdk.maps.MapGestureDetector.onTouchEvent(MapGestureDetector.java:216)
        at com.mapbox.mapboxsdk.maps.MapView.onTouchEvent(MapView.java:425)
        at android.view.View.dispatchTouchEvent(View.java:14309)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3112)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2785)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3118)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2799)
        at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:488)
        at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1871)
        at android.app.Dialog.dispatchTouchEvent(Dialog.java:859)
        at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:446)
        at android.view.View.dispatchPointerEvent(View.java:14568)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6016)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5819)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5310)
E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5367)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5333)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5485)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5341)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5542)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5314)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5367)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5333)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5341)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5314)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8080)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8031)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7992)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:8203)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:220)
        at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
        at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:200)
        at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:8160)
        at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:8242)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
        at android.view.Choreographer.doCallbacks(Choreographer.java:796)
        at android.view.Choreographer.doFrame(Choreographer.java:724)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/Process: Sending signal. PID: 4209 SIG: 9

【问题讨论】:

XML 标签: 尝试在 SO 中搜索 SecurityException getDataNetworkTypeForSubscriber 以查看 Q 和 A 是否可以帮助您。 【参考方案1】:

检查您的 mapbox 版本,因为 https://github.com/mapbox/mapbox-navigation-android/issues/3577 声明他们将在下一个版本(2020 年 9 月)中修复它。

否则,您可以尝试在 build.gradle 中添加 "com.mapbox.mapboxsdk:mapbox-android-telemetry:6.1.0" 作为依赖项

【讨论】:

【参考方案2】:

感谢所有回答的人。我找到了解决方案。如果其他人遇到此问题,您可能需要考虑从 Android 11 降级到另一个版本。

我将我的模拟器从 Android 11 切换到了 Android 9,它运行良好!

来源:Android App Keeps Crashing In Android Studio Emulator

【讨论】:

请不要添加“谢谢”作为答案。相反,您认为最有帮助的 accept the answer。 - From Review 答案不是谢谢......答案是从 Android 11 降级

以上是关于Android Studio 应用程序在触摸 MapView 时崩溃的主要内容,如果未能解决你的问题,请参考以下文章

Android Studio App未经许可或按钮发送图像

Android studio 导入githubproject

Android Studio 学习内容提供器

Android Studio Gradle配置

Android Studio Gradle配置

如何在android studio 3中使用photoview 2.0.0