BluetoothAdapter:Unhandled exception: java.lang.RuntimeException: Can't create handler inside thread
將原本執行在6.0上的程式安裝在4.4的系統上之後出現了一個詭異的異常
BluetoothAdapter:Unhandled exception: java.lang.RuntimeException: Can't create handler inside thread
分析原因發現:
1.在Android 6.0 系統中使用BLE掃描BluetoothAdapter.LeScanCallback回撥方法是執行在主執行緒的
2.然而在Android 4.4 系統中,通過列印日誌發現BluetoothAdapter.LeScanCallback的回撥是執行在了子執行緒
3.然而我在BluetoothAdapter.LeScanCallback回撥方法中,因為建立你了Handler所以導致了此異常的出現
解決方法有兩種如下:
第一種方案:修改Hander構造方法,改為
new Handler(Looper.getMainLooper());
第二種方案:在BluetoothAdapter.LeScanCallback中使用Handler傳送訊息
@Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { Message msg = new Message(); msg.obj = device; msg.what = 1; mHandler.sendMessage(msg); }
相關推薦
BluetoothAdapter:Unhandled exception: java.lang.RuntimeException: Can39;t create handler inside thread
將原本執行在6.0上的程式安裝在4.4的系統上之後出現了一個詭異的異常 BluetoothAdapter:Unhandled exception: java.lang.RuntimeException: Can't create handler inside thread 分析原因發現:
android 提示異常:java.lang.RuntimeException: Can39;t create handler inside thread that has not called
出現此異常,可能是在子執行緒彈Toast/Dialog或者其他了, 切記,Toast/Dialog只能在UI執行緒彈出。 處理的話,要麼子執行緒也可以,要麼都放主執行緒,以下兩種方式分別對應。 Android-在子執行緒中顯示Toast和Dialog Android中有句話說,只能在
轉 在子線程中new Handler報錯--Can39;t create handler inside thread that has not called Looper.prepare()
tst exc 手動 tac new 聯網 clas 如果 read 在子線程中new一個Handler為什麽會報以下錯誤? java.lang.RuntimeException: Can‘t create handler inside thread that has
Android進階(十六)子執行緒呼叫Toast報Can39;t create handler inside thread that has not called Looper.prepare() 錯誤
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
執行緒呼叫Toast出現Can39;t create handler inside thread that has not calledLooper.prepare()問題
解決方法出處https://blog.csdn.net/sunhuaqiang1/article/details/46839045 解決辦法:線上程中的Toast前後加上Looper.prepare()及Looper.loop()。 原因:建立新程序的情況下預設不會建立新的訊息佇列,而Toa
在子執行緒中new Handler報錯--Can39;t create handler inside thread that has not called Looper.prepare()
在子執行緒中new一個Handler為什麼會報以下錯誤? java.lang.RuntimeException: Can't create handler inside thread that has not&
【轉】在子執行緒中new Handler報錯--Can39;t create handler inside thread that has not called Looper.prepare()
在子執行緒中new一個Handler為什麼會報以下錯誤? java.lang.RuntimeException: Can't create handler inside thread that has not ca
【轉】在子線程中new Handler報錯--Can39;t create handler inside thread that has not called Looper.prepare()
ktr 如果 creat .com 問題: 消息隊列 per word int 在子線程中new一個Handler為什麽會報以下錯誤? java.lang.RuntimeException: Can‘t create handler inside thread that
java.lang.SecurityException: Can39;t make field constructor accessible
比較 spa client prev title with o-c and 切換 原本使用GsonConvertor,在Android版本5.1.1上沒有任何問題,結果切換到版本6.0.1上,出現以下所示問題: java.lang.IllegalAr
java.lang.UnsupportedOperationException: Can39;t convert to color: type=0x2 In TextInputLayout
frame tty caller dialog comm ner code appcompat listener when we use TextInputLayout to set setErrorEnabled(true) it throws exception
myeclipse 修改項目名Tomcat啟動項目報錯java.lang.IllegalArgumentException: Can39;t convert argument: null
exce 問題分析 修改項目名 pat clip 啟動項 rim spa core 一、Tomcat啟動報錯:有時候我們會避免項目重名,在導入項目時會修改項目名稱。修改項目名稱後啟動該項目至tomcat,報錯:java.lang.IllegalArgumentExcepti
android Toast提示異常:java.lang.RuntimeException: Can't create handler inside thread that has not called
android Toast提示異常:java.lang.RuntimeException: Can't create handler inside thread that has not
Android Toast顯示 Can't create handler inside thread that has not called Looper.prepare()問題
今天在開發的時候 在子執行緒中呼叫了一個Toast結果報錯 Can’t create handler inside thread that has not called Looper.prepare() 錯誤程式碼示例: public void sho
Can't create handler inside thread that has not called Looper.prepare()解決辦法
像提示說的,新增 Looper.prepare(); Thread action=newThread() { publicvoidrun() { Looper.prepare(); todo(); Looper.loop(); } }; action.
android之Can't create handler inside thread that has not called Looper.prepare()
好久沒遇到這種錯誤,最初都是因為在新開的執行緒中更新UI才出錯,後來一直沒忘記用handler,也就沒用錯誤,今天有出現如下錯誤,程式碼如下:send.setOnClickListener(new OnClickListener() { @Override
異常:Can't create handler inside thread that has not called Looper.prepare()解決辦法
近些日。cocos2dx遊戲專案要接入一個不主流的支付,達到遊戲內跳轉微信充值,在按照某支付文件寫示例demo的時候各種成功,然而蛋疼的就是移植到遊戲內的時候出現問題。異常就是標題Can't create handler inside thread that has not
Android進階(十六)子執行緒呼叫Toast報Can't create handler inside thread that has not called Looper.prepare() 錯誤
原子執行緒呼叫Toast報Can't create handler inside thread that has not called Looper.prepare() 錯誤 今天用子執行緒調Toast報了一個Can't create handler inside thre
Exception in thread "main" java.util.MissingResourceException: Can39;t find bundle for base name Message, locale zh_CN
bundle 描述 str 圖片 ava thread 進行 sage mis 問題描述:今天在進行程序國際化編程時,碰到MissingResourceException異常,大意是沒有找到屬性文件。當時項目目錄如下: 我把兩個屬性文件放到源碼包下,所以會出現問題。 解決
出現java.lang.Exception: java.lang.RuntimeException: java.lang.NoSuchMethodException: com.web.visit.main.ClickVist$VisitMapper.<init>()的問題
圖片 init mapr img 內部類 div ava 執行 沒有 執行mapreduce報錯java.lang.Exception: java.lang.RuntimeException: java.lang.NoSuchMethodException: com.
【完美解決系列】Volley: [1541] NetworkDispatcher.run: Unhandled exception java.lang.NullPointerException
在使用Volley時出現了以下錯誤提示: Volley: [1541] NetworkDispatcher.run: Unhandled exception java.lang.NullPointer