Guest User

Untitled

a guest
Apr 27th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. private Uri[] roomPhotos;
  2. private Uri[] roomAudios;
  3.  
  4. roomPhotos=new Uri[n_rooms];
  5. roomAudios=new Uri[n_rooms];
  6.  
  7. Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  8. startActivityForResult(Intent.createChooser(i, "Select photo"), IMAGE_LOADED);
  9. Intent g = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
  10. startActivityForResult(Intent.createChooser(g, "Select audio"), AUDIO_LOADED);
  11.  
  12. @Override
  13. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  14. super.onActivityResult(requestCode, resultCode, data);
  15. if (requestCode == IMAGE_LOADED && resultCode == RESULT_OK && null != data) {
  16. roomPhotos[tempId]=data.getData();
  17. Log.d("aftroomadd","inserted: "+roomPhotos[tempId]);
  18. Log.d("aftroomadd","id: "+String.valueOf(tempId));
  19. }
  20. else if(requestCode == AUDIO_LOADED && resultCode == RESULT_OK && null != data) {
  21. roomAudios[tempId]=data.getData();
  22. Log.d("aftroomadd","id: "+String.valueOf(tempId));
  23. Log.d("aftroomadd","inserted: "+roomAudios[tempId]);
  24. }
  25. }
  26.  
  27. 04-27 10:25:29.567 14791-14791/? D/aftroomadd: inserted: content://media/external/audio/media/25831
  28. 04-27 10:25:29.567 14791-14791/? D/aftroomadd: id: 0
  29. 04-27 10:25:29.592 14791-14791/? D/aftroomadd: inserted: content://media/external/images/media/16365
  30. 04-27 10:25:29.592 14791-14791/? D/aftroomadd: id: 0
  31.  
  32. @Override
  33. public boolean onOptionsItemSelected(MenuItem item) {
  34. int id = item.getItemId();
  35. if(id==R.id.accept) {
  36. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  37. SharedPreferences.Editor edit = prefs.edit();
  38. File f;
  39. for(int z=0;z<roomTitles.length;z++){
  40. Log.d("aftroomadd","t: "+roomTitles[z]);
  41. Log.d("aftroomadd","p: "+roomPhotos[z]);
  42. Log.d("aftroomadd","a: "+roomAudios[z])
  43. }
  44. for(int i=0;i<roomPhotos.length;i++){
  45. try {
  46. f = new File(roomPhotos[i].getPath());
  47. partJson.put("title", roomTitles[i]);
  48. partJson.put("image", f.getName());
  49. f = new File(roomAudios[i].getPath());
  50. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  51. [...]
  52.  
  53. java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getPath()' on a null object reference
  54.  
  55. 04-27 10:27:11.909 16307-16307/tzz.guidapp D/aftroomadd: t: ff
  56. 04-27 10:27:11.909 16307-16307/tzz.guidapp D/aftroomadd: p: content://media/external/images/media/16365
  57. 04-27 10:27:11.909 16307-16307/tzz.guidapp D/aftroomadd: a: null
  58. 04-27 10:27:11.909 16307-16307/tzz.guidapp D/aftroomadd: t: ttk
  59. 04-27 10:27:11.909 16307-16307/tzz.guidapp D/aftroomadd: p: content://media/external/images/media/16366
  60. 04-27 10:27:11.909 16307-16307/tzz.guidapp D/aftroomadd: a: null
Add Comment
Please, Sign In to add comment