Android廣播錯誤.MainActivity$MyReceiver; no empty constructor

來源:互聯網
上載者:User

標籤:can   tail   anti   oid   tde   需要   instant   color   example   

廣播的定義,如果是內部類,必須為靜態類

http://blog.csdn.net/chdjj/article/details/19496567

下面總結一下作為內部類的廣播接收者在註冊的時候需要注意的地方1.資訊清單檔註冊廣播接收者時,廣播接收者的名字格式需要注意。因為是內部類,所以需要在內部類所在的類與內部類之間加上$符號:
android:name="com.example.brocastdemo.MainActivity$MyReceiver"  

2.內部類在聲明時一定要寫成靜態內部類(class關鍵字前加上static)。否則會拋出類似這樣的異常:

02-19 09:11:14.650: E/AndroidRuntime(1771): java.lang.RuntimeException: Unable to instantiate receiver com.example.brocastdemo.MainActivity$MyReceiver: java.lang.InstantiationException: can‘t instantiate class com.example.brocastdemo.MainActivity$MyReceiver; no empty constructor

 

Android廣播錯誤.MainActivity$MyReceiver; no empty constructor

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.