我正在Android中開發應用程序,並遇到Android框架在試圖實例化嵌套類時拋出java.lang.InstantiationException的問題。 這是場景。無法在sendBroadcast實例化嵌套類(擴展broadcastReceiver)
public class A extends Activity
{
public void onCreate(){
....};
//Class B
public class B extends BroadcastReceiver
{
public void onReceive(...)
}
}
類聲明中的清單文件: ....
類A延伸活動
對不起,縮進。只是找不到用這麼多標籤正確縮進代碼的方法。
- 廣播從服務:
Intent updateIntent = new Intent();
updateIntent.setAction("desired_action");
sendBroadcast(accountPropertyUpdateIntent);
與所有上面給出的東西,代碼被編譯,但在設備上運行,廣播被稱爲後,我得到一個InstantiationException說不能實例化pacakage.A $ B,並且dalvik說沒有找到。
現在這整個場景在Android 2.2上工作,但不知何故這在2.1上失敗。
我不知道到底發生了什麼。我需要幫助。也許一些基本的東西是我失蹤的。
任何人都可以幫我嗎?提前致謝。
我敢肯定,你不能有一個嵌套的broadcastreciever類。你爲什麼要這樣做? – Falmarri 2010-11-24 16:40:35
需要A類內的broadcastreceiver,以便在某些廣播事件中,B類可以直接訪問A類的成員並相應地更新UI。 – Puneet 2010-11-25 03:11:03