我試圖發送一個基本上包含設備上文件路徑的array of Strings
。首先是用戶Selects Picture 1
,然後是Select Picture 2
。一旦用戶完成該數組然後被加載並傳遞到下一個活動。當試圖收到變量返回NullPointer
。在Android中的兩個活動之間傳遞String Array時的NullPointer
MainActivity:
case SELECT_PICTURE1:
if (resultCode == RESULT_OK) {
// code here that gets the image path
// String leftImagePath contains the path of selected Image
// Used toast to display the image path and it is not null
finished = true;
}
break;
case SELECT_PICTURE2:
if (resultCode == RESULT_OK) {
//similar to Select Picture 1
// String rightImagePath contains the path of selected Image
if (finished == true) {
Bundle b = new Bundle();
b.putStringArray("stringArray", new String[] {
LeftImageString, RightImageString });
Intent i = new Intent(MainActivity.this, modifiedImage.class);
i.putExtras(b);
// finished = false;
}
}
break;
ModifiedImage類:
Intent intent = getIntent();
_imagesPath = intent.getStringArrayExtra("IMAGES_PATH");
Bundle b= this.getIntent().getExtras();
_userImagePath = b.getStringArray("stringArray");
if (_imagesPath == null) {
for (int i = 0; i <= 1; i++) {
//null pointer on the following line because _userImagePath contains nothing.
_imagesPath[i] = _userImagePath[i];
_originalBitmaps[i] = BitmapFactory.decodeFile(_imagesPath[i]);
}
}
有誰知道它是什麼,我做錯了?
你在哪裏傳遞'從第一Activity.also IMAGES_PATH'鍵獲得軟件包之前添加null檢查和第二個活動的意圖值 –
@ User1204501我認爲他在他的評論 – Trikaldarshi