1

我正在努力不断地做一份工作。对于这项工作,我正在使用处理程序并以恒定的时间间隔递归地调用此处理程序。我的代码在 Android 版本 4.3 的三星 Galaxy Note 2 中运行,但不能在 Android 版本 4.4.2 的 Nexus 5 中运行。我被这个问题困住了。我正在输入代码和错误日志,请帮忙。祝你有美好的一天。(我正在简化代码,因此您可以轻松分析,但是如果您愿意,我可以在这里编写所有代码。)(另外,由于它的大小,我没有写所有的错误日志。)

代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tram);

    some initializations...

    runnable = new Runnable() {
        @Override
        public void run() {
            if (!isMapDataLoading) {
                // update the trams' markers
                loadMapDataIfNeeded(true);
            }
            handler.postDelayed(this, handlerDelayInterval);
        }
    };

    // some settings...
}

@Override
protected void onResume() {
    super.onResume();
    setUpLocationClientIfNeeded();
    locationClient.connect();
    if (!isHandlerRun) {
        handler.postDelayed(runnable, handlerDelayInterval);
        isHandlerRun = true;
    }
}

@Override
protected void onPause() {
    super.onPause();
    if (locationClient != null) {
        locationClient.disconnect();
    }
    handler.removeCallbacks(runnable);
    isHandlerRun = false;
}

@Override
public void onConnected(Bundle bundle) {
    locationClient.requestLocationUpdates(REQUEST,
            this);    // LocationListener
    setUpMapIfNeeded();
}

@Override
public void onDisconnected() {
    Log.i(TAG, "Google Play Services Client disconnected.");
}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    Toast.makeText(this, R.string.could_not_connect_map_services, Toast.LENGTH_LONG).show();
}

private void setUpMapIfNeeded() {
            // load map data
            if (hasConnection) {
                loadMapDataIfNeeded(true);
            }
}

private synchronized void loadMapDataIfNeeded(final boolean isMapDataUpdateNeeded) {
    if (!isMapDataLoaded || isMapDataUpdateNeeded) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                isMapDataLoading = true;
            }

            @Override
            protected Void doInBackground(Void... args) {
                try {
                    getting JSON array...
                    JSONArray jsonArray = new JSONArray(tramsData);

                    for (int i = 0; i < jsonArray.length(); i++) {
                        setting a tram object...
                        MarkerOptions tramMarkerOptions;
                        if (tram.getMarkerOptions() != null) {
                            tramMarkerOptions = tram.getMarkerOptions();
                        } else {
                            tramMarkerOptions = new MarkerOptions();
                            tram.setMarkerOptions(tramMarkerOptions);
                        }
errors point this point                            tramMarkerOptions.icon(BitmapDescriptorFactory.fromBitmap(bmpResult))
                                .position(new LatLng(tram.getLatitudeY(), tram.getLongitudeX()));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);
                // map data has been loaded
                isMapDataLoaded = true;
                isMapDataLoading = false;
            }
        }.execute();
    }
}

错误日志:

E/art﹕ Tried to mark 0x00000024 not contained by any spaces
E/art﹕ Attempting see if it's a bad root
E/art﹕ Found invalid root: 0x00000024
E/art﹕ Visiting method 'java.lang.Void com.modilisim.estram.tram.TramActivity$3.doInBackground(java.lang.Void[])' at dex PC 0x014d (native PC 0x4886ba43) in VReg: 0
A/art﹕ art/runtime/gc/collector/mark_sweep.cc:463] Can't mark bad root
A/art﹕ art/runtime/runtime.cc:203] Runtime aborting...
A/art﹕ art/runtime/runtime.cc:203] Aborting thread:
A/art﹕ art/runtime/runtime.cc:203] "AsyncTask #2" prio=5 tid=27 Runnable
A/art﹕ art/runtime/runtime.cc:203]   | group="main" sCount=0 dsCount=0 obj=0x65592ab8 self=0x4af61090
A/art﹕ art/runtime/runtime.cc:203]   | sysTid=2377 nice=10 cgrp=apps/bg_non_interactive sched=0/0 handle=0x4f22f2e8
A/art﹕ art/runtime/runtime.cc:203]   | state=R schedstat=( 163193439 63608076 121 ) utm=10 stm=6 core=0 HZ=100
A/art﹕ art/runtime/runtime.cc:203]   | stack=0x50bdf000-0x50be3000 stackSize=1040KB
A/art﹕ art/runtime/runtime.cc:203]   native: art::Thread::DumpStack(std::ostream&) const+87 [0x41655edc] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x4164e06c] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::Runtime::Abort()+79 [0x4164e5fc] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::LogMessage::~LogMessage()+505 [0x414fb93a] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::gc::collector::MarkSweep::MarkLargeObject(art::mirror::Object const*, bool)+219 [0x41563814] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x415638f2] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x4156392c] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x416568d0] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x41656a2a] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::StackVisitor::WalkStack(bool)+143 [0x416543f0] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::Thread::VisitRoots(void (*)(art::mirror::Object const*, void*), void*)+199 [0x416557fc] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x41562e16] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::ThreadList::RunCheckpoint(art::Closure*)+203 [0x41661650] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::gc::collector::MarkSweep::MarkRootsCheckpoint(art::Thread*)+65 [0x4156141a] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::gc::collector::MarkSweep::MarkingPhase()+127 [0x415611f4] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::gc::collector::GarbageCollector::Run()+167 [0x4156025c] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::gc::Heap::CollectGarbageInternal(art::gc::collector::GcType, art::gc::GcCause, bool)+425 [0x4156920a] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x4162e700] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   at java.lang.Runtime.gc(Native method)
A/art﹕ art/runtime/runtime.cc:203]   at com.android.internal.os.BinderInternal.forceGc(BinderInternal.java:89)
A/art﹕ art/runtime/runtime.cc:203]   at com.android.internal.os.BinderInternal.forceBinderGc(BinderInternal.java:93)
A/art﹕ art/runtime/runtime.cc:203]   at android.os.Parcel.nativeWriteStrongBinder(Native method)
A/art﹕ art/runtime/runtime.cc:203]   at android.os.Parcel.writeStrongBinder(Parcel.java:533)
A/art﹕ art/runtime/runtime.cc:203]   at ewg.onTransact(SourceFile:108)
A/art﹕ art/runtime/runtime.cc:203]   at android.os.Binder.transact(Binder.java:361)
A/art﹕ art/runtime/runtime.cc:203]   at com.google.android.gms.maps.model.internal.a$a$a.b(unavailable:-1)
A/art﹕ art/runtime/runtime.cc:203]   at com.google.android.gms.maps.model.BitmapDescriptorFactory.fromBitmap(unavailable:-1)
A/art﹕ art/runtime/runtime.cc:203]   at com.modilisim.estram.tram.TramActivity$3.doInBackground(TramActivity.java:356)
A/art﹕ art/runtime/runtime.cc:203]   at com.modilisim.estram.tram.TramActivity$3.doInBackground(TramActivity.java:279)
A/art﹕ art/runtime/runtime.cc:203]   at android.os.AsyncTask$2.call(AsyncTask.java:288)
A/art﹕ art/runtime/runtime.cc:203]   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
A/art﹕ art/runtime/runtime.cc:203]   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
A/art﹕ art/runtime/runtime.cc:203]   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
A/art﹕ art/runtime/runtime.cc:203]   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
A/art﹕ art/runtime/runtime.cc:203]   at java.lang.Thread.run(Thread.java:811)
A/art﹕ art/runtime/runtime.cc:203] Dumping all threads without appropriate locks held: thread list lock mutator lock
A/art﹕ art/runtime/runtime.cc:203] All threads:
A/art﹕ art/runtime/runtime.cc:203] DALVIK THREADS (32):
A/art﹕ art/runtime/runtime.cc:203] "main" prio=5 tid=1 Native
A/art﹕ art/runtime/runtime.cc:203]   | group="main" sCount=1 dsCount=0 obj=0x64635ac8 self=0x41709af0
A/art﹕ art/runtime/runtime.cc:203]   | sysTid=2272 nice=0 cgrp=apps sched=0/0 handle=0x40076154
A/art﹕ art/runtime/runtime.cc:203]   | state=S schedstat=( 1528951446 422214649 4061 ) utm=121 stm=31 core=0 HZ=100
A/art﹕ art/runtime/runtime.cc:203]   | stack=0xbe04c000-0xbe050000 stackSize=8MB
A/art﹕ art/runtime/runtime.cc:203]   native: android::Looper::pollOnce(int, int*, int*, void**)+92 [0x40113869] (libutils.so)
A/art﹕ art/runtime/runtime.cc:203]   native: android::NativeMessageQueue::pollOnce(_JNIEnv*, int)+22 [0x401bc121] (libandroid_runtime.so)
A/art﹕ art/runtime/runtime.cc:203]   native: oatexec+18049404 [0x634a197c] (system@framework@boot.oat)
A/art﹕ art/runtime/runtime.cc:203]   at android.os.MessageQueue.nativePollOnce(Native method)
A/art﹕ art/runtime/runtime.cc:203]   at android.os.MessageQueue.next(MessageQueue.java:138)
A/art﹕ art/runtime/runtime.cc:203]   at android.os.Looper.loop(Looper.java:123)
A/art﹕ art/runtime/runtime.cc:203]   at android.app.ActivityThread.main(ActivityThread.java:5017)
A/art﹕ art/runtime/runtime.cc:203]   at java.lang.reflect.Method.invoke(Native method)
A/art﹕ art/runtime/runtime.cc:203]   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
A/art﹕ art/runtime/runtime.cc:203]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
A/art﹕ art/runtime/runtime.cc:203]
A/art﹕ art/runtime/runtime.cc:203] "Thread pool worker 1" prio=4 tid=2 Native (still starting up)
A/art﹕ art/runtime/runtime.cc:203]   | group="" sCount=1 dsCount=0 obj=0x00000000 self=0x44161c70
A/art﹕ art/runtime/runtime.cc:203]   | sysTid=2278 nice=0 cgrp=apps sched=0/0 handle=0x472ef5a8
A/art﹕ art/runtime/runtime.cc:203]   | state=S schedstat=( 7052297 14719996 59 ) utm=0 stm=0 core=0 HZ=100
A/art﹕ art/runtime/runtime.cc:203]   | stack=0x44001000-0x44005000 stackSize=1024KB
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x4417867c] ([anon:libc_malloc])
A/art﹕ art/runtime/runtime.cc:203]   (no managed stack frames)
A/art﹕ art/runtime/runtime.cc:203]
A/art﹕ art/runtime/runtime.cc:203] "Thread pool worker 0" prio=4 tid=3 Native (still starting up)
A/art﹕ art/runtime/runtime.cc:203]   | group="" sCount=1 dsCount=0 obj=0x00000000 self=0x471f1a78
A/art﹕ art/runtime/runtime.cc:203]   | sysTid=2277 nice=0 cgrp=apps sched=0/0 handle=0x4170f748
A/art﹕ art/runtime/runtime.cc:203]   | state=S schedstat=( 3759112 14592449 60 ) utm=0 stm=0 core=0 HZ=100
A/art﹕ art/runtime/runtime.cc:203]   | stack=0x43f01000-0x43f05000 stackSize=1024KB
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x4417867c] ([anon:libc_malloc])
A/art﹕ art/runtime/runtime.cc:203]   (no managed stack frames)
A/art﹕ art/runtime/runtime.cc:203]
A/art﹕ art/runtime/runtime.cc:203] "Thread pool worker 2" prio=4 tid=4 Native (still starting up)
A/art﹕ art/runtime/runtime.cc:203]   | group="" sCount=1 dsCount=0 obj=0x00000000 self=0x471f1cf8
A/art﹕ art/runtime/runtime.cc:203]   | sysTid=2279 nice=0 cgrp=apps sched=0/0 handle=0x44161a28
A/art﹕ art/runtime/runtime.cc:203]   | state=S schedstat=( 4733329 15842035 61 ) utm=0 stm=0 core=0 HZ=100
A/art﹕ art/runtime/runtime.cc:203]   | stack=0x47763000-0x47767000 stackSize=1024KB
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x4417867c] ([anon:libc_malloc])
A/art﹕ art/runtime/runtime.cc:203]   (no managed stack frames)
A/art﹕ art/runtime/runtime.cc:203]
A/art﹕ art/runtime/runtime.cc:203] "Signal Catcher" daemon prio=5 tid=5 WaitingInMainSignalCatcherLoop
A/art﹕ art/runtime/runtime.cc:203]   | group="system" sCount=1 dsCount=0 obj=0x655379c8 self=0x472eedb0
A/art﹕ art/runtime/runtime.cc:203]   | sysTid=2280 nice=0 cgrp=apps sched=0/0 handle=0x44161510
A/art﹕ art/runtime/runtime.cc:203]   | state=S schedstat=( 398021 103646 1 ) utm=0 stm=0 core=0 HZ=100
A/art﹕ art/runtime/runtime.cc:203]   | stack=0x47863000-0x47867000 stackSize=1016KB
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x4165206b] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::SignalCatcher::WaitForSignal(art::Thread*, art::SignalSet&)+46 [0x416523d7] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: art::SignalCatcher::Run(void*)+176 [0x4165394d] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: __thread_entry+72 [0x40098170] (libc.so)
A/art﹕ art/runtime/runtime.cc:203]   native: pthread_create+240 [0x40098308] (libc.so)
A/art﹕ art/runtime/runtime.cc:203]   (no managed stack frames)
A/art﹕ art/runtime/runtime.cc:203]
A/art﹕ art/runtime/runtime.cc:203] "JDWP" daemon prio=5 tid=6 WaitingInMainDebuggerLoop
A/art﹕ art/runtime/runtime.cc:203]   | group="system" sCount=1 dsCount=0 obj=0x65532d90 self=0x472edb60
A/art﹕ art/runtime/runtime.cc:203]   | sysTid=2282 nice=0 cgrp=apps sched=0/0 handle=0x472ed918
A/art﹕ art/runtime/runtime.cc:203]   | state=S schedstat=( 1269687 1076354 9 ) utm=0 stm=0 core=2 HZ=100
A/art﹕ art/runtime/runtime.cc:203]   | stack=0x47961000-0x47965000 stackSize=1016KB
A/art﹕ art/runtime/runtime.cc:203]   native: art::JDWP::JdwpState::Run()+378 [0x415a45f7] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: ??? [0x415a5873] (libart.so)
A/art﹕ art/runtime/runtime.cc:203]   native: __thread_entry+72 [0x40098170] (libc.so)
A/art﹕ art/runtime/runtime.cc:203]   native: pthread_create+240 [0x40098308] (libc.so)
A/art﹕ art/runtime/runtime.cc:203]   (no managed stack frames)
4

2 回答 2

3

我意识到这个问题的发生是因为我谈到的 Nexus 5 具有 ART 的运行时。此外,“ART”一词出现在错误日志中。我已将 Nexus 5 的运行时更改为 Dalvik,问题已消失。我认为当前的 ART 实现存在错误。

于 2014-04-22T11:31:09.457 回答
0

这是否解决了它并完成了您的需要?

    runnable = new Runnable() {
        @Override
        public void run() {
            if (!isMapDataLoading) {
                // update the trams' markers
                loadMapDataIfNeeded(true);
            }
            try {
               Thread.sleep(handlerDelayInterval);
            } catch (InterruptedException ignore){}
            run();
        }
    };

你要无限循环吗?

于 2014-04-21T14:51:51.527 回答