我已經創建了名爲「EventFragment」的listFragment類,我需要在其click事件上傳遞數據對象以傳遞drawerActivity類(片段類),然後我需要將該對象傳遞給另一個名爲EventDisplayActivity類的活動。我可以管理獲取數據對象到drawerActivity類,但我不能將它發送到EventDisplayActivity類。將數據對象傳遞給另一活動的活動(片段 - >其活動 - >新活動)
//DrawerActivity code
@Override
public void OnEventItemClick(ZEvent zEventObject) {
Log.i("URI uri", ""+zEventObject.getEventName());
zEventItem = (ZEvent)zEventObject;
Bundle b = new Bundle();
b.putParcelable("EVENT_ITEM", zEventItem);
Intent i = new Intent(DrawerActivity.this, EventDisplayActivity.class);
i.putExtra("DUMMY","dummytext");
i.putExtras(b);
startActivity(i);
}
// EventDisplayActivity
@Override
protected void onInit(ModelBase... data) {
System.out.println("onInit() Called in Event Display Activity");
SharedPreferences sessionkey = getApplicationContext().getSharedPreferences("session_detail", Context.MODE_PRIVATE);
session_token = sessionkey.getString("session", "");
logged_user_type = sessionkey.getString("user_type", "");
logged_user_id = sessionkey.getString("user_id", "");
Intent i = getIntent();
Bundle extras = i.getExtras();
ZEvent zEventbundle = extras.getParcelable("EVENT_ITEM");
mProposalId = zEventbundle.getProposalID();
String mDummy = getIntent().getStringExtra("DUMMY");
Log.i("id>>>",""+mProposalId +"Dummy"+mDummy);
params = new RequestParams();
params.put("token", session_token);
params.put("proposal_id", mProposalId);
mApiClient.getView(eventViewURL, params, eventResponse);
}
//LOgCat
java.lang.RuntimeException: Unable to start activity
ComponentInfo{gg.zing/gg.zin.zing.events.activities.EventDisplayActivity}: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
at gg.zin.zing.events.activities.EventDisplayActivity.onInit(EventDisplayActivity.java:431)
肯定。我沒有將ZEvent(Model class)實現爲Parcelable。您建議發送數據對象的方式也是正確的。感謝您的幫助 – cham