在Android Bundle中发送OpenCV Mat

时间:2014-05-05 18:08:17

标签: java android opencv android-intent bundle

我想在Bundle中发送org.opencv.core.Mat对象。我决定使用Gson,因为它看似简单快捷。

家长活动:

public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
        case R.id.areas_creator_activity:
            Gson gs = new Gson();
            String stringBackground = gs.toJson(guard.getBackground());
            Intent intentAreasCreatorActivity = new Intent(MainActivity.this, AreasCreatorActivity.class);
            intentAreasCreatorActivity.putExtra("background", stringBackground);
            startActivityForResult(intentAreasCreatorActivity,2);
            break;
      }
        return true;

 }

儿童活动:

public void onResume()
{
    super.onResume();

    String jsonMyObject= new String();
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
       jsonMyObject = extras.getString("myObject");
    }
    Gson gs = new Gson();
    Mat myObject = gs.fromJson(jsonMyObject, Mat.class);
    background=myObject;
    //Log.i("@string/app_name", background.toString());        
}

logcat的

    05-05 19:59:12.286: E/AndroidRuntime(7961): FATAL EXCEPTION: main
    05-05 19:59:12.286: E/AndroidRuntime(7961): java.lang.RuntimeException: Unable to resume activity {pl.net.lach.pracainz/pl.net.lach.pracainz.AreasCreatorActivity}: java.lang.NullPointerException

当我在背景对象(注释行)上使用Mat metod时出现问题。怎么了?

0 个答案:

没有答案