Java 尝试使用Intent putExtra方法时出现运行时错误

Java 尝试使用Intent putExtra方法时出现运行时错误,java,android,android-intent,Java,Android,Android Intent,我想将OAScene场景对象发送到下一个活动类,但我不能。如果我没有使用putExtra方法打开其他activity类,它就会工作。。。但在我的情况下,我需要发送对象 这是密码 public void setScene(OAScene scene) { final OAScene _scene = scene; this.currentScene = scene; setColor(color_black); double dis; dis = Ca

我想将OAScene场景对象发送到下一个活动类,但我不能。如果我没有使用putExtra方法打开其他activity类,它就会工作。。。但在我的情况下,我需要发送对象

这是密码

public void setScene(OAScene scene) {
    final OAScene _scene = scene; 
    this.currentScene = scene;
    setColor(color_black);

    double dis; 
    dis = CalculationByDistance(latitudeOri, latitudeOri, scene.getLatitude(), scene.getLongitude());

    // Set the text fields of the notification bubble to match the data of
    // the selected scene.
    popup_name.setText("Name: " + scene.getName());
    popup_text.setText("Distance: " + dis + "m");

    more_info.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
             OAScene scene=_scene; 
             Intent FacilityIntent;
             FacilityIntent = new Intent(getContext(), MapViewActivity.class);
             FacilityIntent.putExtra("scene", _scene);
             getContext().startActivity(FacilityIntent);
        }
     });
}
日志

代码接收意图:

Intent i = getIntent();
        OAScene scene = (OAScene)i.getSerializableExtra("scene");
试试这个

 facilityIntent= new Intent(YourCurrectActivity.this, MapViewActivity.class);
 facilityIntent.putExtra("scene", _scene);
 startActivity(facilityIntent);
在第二个活动中,您可以使用

getIntent().getSerializableExtra("scene");
  • 尝试按照以下步骤为预定义类创建对象。使用facilityIntent代替facilityIntent

一个选项是让自定义类实现可序列化接口,然后您可以使用intent#putExtra()方法的putExtra(Serializable..)变体在intent extra中传递对象实例

伪代码:

//to pass :
   intent.putExtra("MyClass", obj);  

// to retrieve object in second Activity
getIntent().getSerializableExtra("MyClass");

有关更多说明,请参阅。

您能否说明您是如何接收
意图的?你一定是做错了什么,或者当“场景”被传递到方法中时为空。请发布ddms日志,以及你如何接收的代码intent@codeMagic我用log和receiving intent Code更新了我的问题帖子您是否为您的可序列化类设置了默认构造函数?另外,这可能不是您的问题,但变量名应该以小写字母开头;)我已经在自定义类上设置了序列化
//to pass :
   intent.putExtra("MyClass", obj);  

// to retrieve object in second Activity
getIntent().getSerializableExtra("MyClass");