Android Studio中的RejectedExecutionException

时间:2016-05-10 10:48:25

标签: android sdk navigation here-api

我的应用程序(使用HERE Android SDK)在进行模拟转弯导航时崩溃,异常日志如下,请告诉我们如何解决它。

  

设备型号:SM-G9008V
  SDK:5.0 ----------- java.util.concurrent.RejectedExecutionException:   任务android.os.AsyncTask$3@36d584c9被拒绝   java.util.concurrent.ThreadPoolExecutor@23d4f7ce [正在运行,池大小=   9,活动线程= 9,排队任务= 128,完成任务= 828]       java.util.concurrent.ThreadPoolExecutor中的$ AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2011)       java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:793)       java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1339)       android.os.AsyncTask.executeOnExecutor(AsyncTask.java:590)       com.nokia.maps.bf.c(LocationRestHandler.java:207)       com.nokia.maps.bf.b(LocationRestHandler.java:198)       com.nokia.maps.dn.b(PlacesReverseGeocodeRequest.java:256)       com.nokia.maps.dn.a(PlacesReverseGeocodeRequest.java:28)       com.nokia.maps.dn $ 1.run(PlacesReverseGeocodeRequest.java:104)       android.os.Handler.handleCallback(Handler.java:739)       android.os.Handler.dispatchMessage(Handler.java:95)       android.os.Looper.loop(Looper.java:145)       android.app.ActivityThread.main(ActivityThread.java:5835)       java.lang.reflect.Method.invoke(Native方法)       java.lang.reflect.Method.invoke(Method.java:372)       com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1399)       com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

3 个答案:

答案 0 :(得分:2)

您是否同时发出了多个请求?您似乎发出了太多请求并超出了未完成的最大数量:

java.util.concurrent.ThreadPoolExecutor@23d4f7ce [正在运行,池大小= 9,活动线程= 9,排队任务= 128,已完成任务= 828]

你在导航代码中做什么?你可以发一个片段吗?

答案 1 :(得分:0)

  

为什么我会收到此错误消息?

如果您已超过ThreadPoolExecutor可排队的任务数,则会收到此错误消息。引发RejectedExecutionException的唯一时间是ThreadPoolExecutor。AbortPolicy是默认的RejectedExecutionHandler

引用javadocs

  

如果请求无法排队,则会创建一个新线程,除非这样   会超过maximumPoolSize,在这种情况下,任务将是   拒绝。

有最多的任务。在此处查看此问题/答案:Is there a limit of AsyncTasks to be executed at the same time?

答案 2 :(得分:0)

@David,下面是代码片段:

if(navigationManager == null) {
            navigationManager = NavigationManager.getInstance();
            navigationManager.setMap(map);
        }

        // start listening to navigation events
        instructListener = new InstructListener();
        navigationManager.addNewInstructionEventListener(
                new WeakReference<NavigationManager.NewInstructionEventListener>(instructListener));

        // start listening to position events
        if (naviPositionListener == null) {
            naviPositionListener = new NaviPositionListener();
        }
        navigationManager.addPositionListener(
                new WeakReference<NavigationManager.PositionListener>(naviPositionListener));

        if (maneuverEventListener == null) {
            maneuverEventListener = new ManeuverEventListener();
        }
        navigationManager.addManeuverEventListener(
                new WeakReference<NavigationManager.ManeuverEventListener>(maneuverEventListener));


        if (myNavigationManagerEventListener == null) {
            myNavigationManagerEventListener = new MyNavigationManagerEventListener();
        }
        navigationManager.addNavigationManagerEventListener(new WeakReference<NavigationManager.NavigationManagerEventListener>(myNavigationManagerEventListener));

        if (rerouteListener == null) {
            rerouteListener = new MyRerouteListener();
        }
        navigationManager.addRerouteListener(new WeakReference<RerouteListener>(rerouteListener));

        if (safetySpotListener == null) {
            safetySpotListener = new MySafetySpotListener();
        }
        navigationManager.addSafetySpotListener(new WeakReference<NavigationManager.SafetySpotListener>(safetySpotListener));

        //add realistic view listener
        navigationManager.setRealisticViewMode(NavigationManager.RealisticViewMode.DAY);
        navigationManager.addRealisticViewAspectRatio(NavigationManager.AspectRatio.AR_4x3);

        if (realisticViewListener == null) {
            realisticViewListener = new MyRealisticViewListener();
        }
        navigationManager.addRealisticViewListener(
                new WeakReference<NavigationManager.RealisticViewListener>(realisticViewListener));


        //set map udpate mode
        navigationManager.setMapUpdateMode(NavigationManager.MapUpdateMode.ROADVIEW);
        navigationManager.setTrafficAvoidanceMode(NavigationManager.TrafficAvoidanceMode.DISABLE);

        //set natural guidance mode
        EnumSet<NavigationManager.NaturalGuidanceMode> modeset = navigationManager.getNaturalGuidanceMode();
        modeset.add(NavigationManager.NaturalGuidanceMode.TRAFFIC_LIGHT);
        modeset.add(NavigationManager.NaturalGuidanceMode.STOP_SIGN);
        modeset.add(NavigationManager.NaturalGuidanceMode.JUNCTION);

        navigationManager.setNaturalGuidanceMode(modeset);

        // add gps signal listener
        if (gpsSignalListener == null) {
            gpsSignalListener = new MyGpsSignalListener();
        }
        navigationManager.addGpsSignalListener(new WeakReference<NavigationManager.GpsSignalListener>(gpsSignalListener));


        if (speedWarningListener == null) {
            speedWarningListener = new MySpeedWarningListener();
        }
        navigationManager.addSpeedWarningListener(new WeakReference<NavigationManager.SpeedWarningListener>(speedWarningListener));

        //add lane info listener
        if (laneInfoListener == null) {
            laneInfoListener = new MyLaneInfoListener();
        }
        navigationManager.addLaneInfoListener(new WeakReference<NavigationManager.LaneInfoListener>(laneInfoListener));


        navigationManager.getRoadView().setOrientation(NavigationManager.RoadView.Orientation.DYNAMIC);
        navigationManager.getRoadView().addListener(new WeakReference<NavigationManager.RoadView.Listener>(roadViewListener));


        //start navigation
        long speed = 60; // meter per second
    navigationManager.simulate(mapRoute.getRoute(), speed);