0

我创建了名为“EventFragment”的 listFragment 类,我需要在其点击事件上传递数据对象以传递抽屉活动类(片段类),然后我需要将该对象传递给另一个名为 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)
4

2 回答 2

0

我假设您的 ZEvent 实现了 Parcelable... 如果是这样,则使用 putExtra 输入意图(而不是创建新的 Bundle 并使用 putExtras),并使用 getParcelableExtra 以相同的方式提取。

// Put     
final Intent intent = new Intent(context, <class>);
intent.putExtra("MY_EVENT", obj); // <-- Should be parcelable
// Get.
ZEvent obj = intent.getParcelableExtra("MY_EVENT");
于 2013-08-28T06:26:28.473 回答
-1

您还可以在用于将数据保存在静态字段中的类中定义静态属性。

public class AppData{
    public static String user = "Ben";
}

你可以像这样使用它:

public void setUser(String user){
    AppData.user = user;
}
于 2013-08-28T10:51:26.613 回答