2017-05-11 20 views
-2

カメラを使用してその画像を再度変更しようとすると、最初に画像を選択して画像ビューに設定したときに、画像が正しく表示された場合は、次のように表示されます。nullpointer exceptionエラー。私ヌルポインタ例外Uri.getmethod();

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 
    if (requestCode == REQUEST_CAMERA) {`enter code here` 
     if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
      openCamera(); 
     } else { 
      Toast.makeText(getActivity().getApplicationContext(), "You need to grant camera permission to use camera", Toast.LENGTH_LONG).show(); 
     } 
    } 
} 
@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == REQUEST_IMAGE_CAMERA && resultCode == RESULT_OK) { 
     dealTakePhoto(); 
    } else { 

     Toast.makeText(getActivity().getApplicationContext(), "Unable to take picture", Toast.LENGTH_SHORT).show(); 
    } 
} 

private void openCamera() { 
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    uri = PhotoUtil.createImageFile(); 
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { 
     takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, 
       uri); 
     startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAMERA); 
    } 
} 

private void dealTakePhoto() { 
    scaledFile = ImageCompress.scal(uri); 
    Bitmap bitmap = BitmapFactory.decodeFile(scaledFile.getAbsolutePath()); 
    String encodeImage = getStringImage(bitmap); 
    picCncoded = encodeImage; 
    Log.d("DEBUG", "dealTakePhoto: " + encodeImage + "end"); 
    float oldSize = (float) new File(uri.getPath()).length()/1024/1024; 
    float newSize = (float) scaledFile.length()/1024; 
    String mCurrentPhotoPath = uri.getPath(); 

    Bitmap originalImage = BitmapFactory.decodeFile(mCurrentPhotoPath); 
    int width = originalImage.getWidth()*2/4; // ((display.getWidth()*20)/100) 
    int height = originalImage.getHeight()*2/4;// ((display.getHeight()*30)/100) 
    pic.setImageBitmap(Bitmap.createScaledBitmap(originalImage, width, height, true)); 
} 

画像圧縮クラス

public static File scal(Uri fileUri){ 
    String path = fileUri.getPath(); 
    File outputFile = new File(path); 
    long fileSize = outputFile.length(); 
    final long fileMaxSize = 200 * 1024; 
    if (fileSize >= fileMaxSize) { 
      BitmapFactory.Options options = new BitmapFactory.Options(); 
      options.inJustDecodeBounds = true; 
      BitmapFactory.decodeFile(path, options); 
      int height = options.outHeight; 
      int width = options.outWidth; 

      double scale = Math.sqrt((float) fileSize/fileMaxSize); 
      options.outHeight = (int) (height/scale); 
      options.outWidth = (int) (width/scale); 
      options.inSampleSize = (int) (scale + 0.5); 
      options.inJustDecodeBounds = false; 

      Bitmap bitmap = BitmapFactory.decodeFile(path, options); 
      outputFile = new File(PhotoUtil.createImageFile().getPath()); 
      FileOutputStream fos = null; 
      try { 
       fos = new FileOutputStream(outputFile); 
       bitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos); 
       fos.close(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      Log.d("", "sss ok " + outputFile.length()); 
      if (!bitmap.isRecycled()) { 
       bitmap.recycle(); 
      }else{ 
       File tempFile = outputFile; 
       outputFile = new File(PhotoUtil.createImageFile().getPath()); 
       PhotoUtil.copyFileUsingFileChannels(tempFile, outputFile); 
      } 

     } 
    return outputFile; 

Logcatエラーを助けてください。

E/AndroidRuntime:致命的な例外:メイン プロセス:in.esla.rwss_customer、PID:864 java.lang.RuntimeException:活性 を再開することができません{in.esla.rwss_customer/in.esla.rwss_customer .LiveTrackScreen}: java.lang.RuntimeException:結果の配信に失敗しました ResultInfo {who = null、request = 196609、result = -1、data = null}アクティビティ {in.esla.rwss_customer/in.esla.rwss_customer。 LiveTrackScreen}: java.lang.NullPointerException:nullオブジェクトに仮想メソッド 'java.lang.String android.net.Uri.getPath()'を呼び出そうとしています 参照 でandroid.app.ActivityThread.performResumeActivity(ActivityThread.java:3136) でandroid.app.ActivityThread.handleResumeActivity(ActivityThread.java:3167) android.app.ActivityThread.handleLaunchActivity(ActivityThread.javaで:android.app.ActivityThread.access $ 1000〜2514) android.os.Handler.dispatchMessageで(ActivityThread.java:153) でandroid.app.ActivityThread $ H.handleMessage(ActivityThread.java:1373) (ハンドラ.java:102) とandroid.os.Looper.loop(Looper.java:154) のandroid.app.ActivityThread.main(ActivityThread.java:5527) のjava.lang.reflect.Method.invoke(ネイティブメソッド) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit。 java:738) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628) 原因:java.lang.RuntimeException:結果の配信が失敗しました ResultInfo {who = null、request = 196609、result = -1、data = null} {in.esla.rwss_customer/in.esla.rwss_customer.LiveTrackScreen}: java.lang.NullPointerException:仮想メソッドを呼び出そうとしました 'java.lang.String android.net.Uri nullオブジェクトの.getPath() ' ref android.app.ActivityThread.handleResumeActivityでandroid.app.ActivityThread.deliverResults android.app.ActivityThread.performResumeActivity(ActivityThread.java:3122)で(ActivityThread.java:3742) (ActivityThread.java:3167で をレンスandroid.app.ActivityThread.access $ 1000〜) でandroid.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2514) (ActivityThread.java:153) android.app.ActivityThread $ H.handleMessage(ActivityThreadで。 java:1373)android.os.Handler.dispatchMessage(Handler.java:102)の android.os.Looper.loop(Looper.java:154)の android.app.ActivityThread.main(ActivityThread。Javaの:5527) java.lang.reflect.Method.invoke(ネイティブメソッド) で com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:738) でcom.android.internalで。 os.ZygoteInit.main(ZygoteInit.java:628) 原因:java.lang.NullPointerException:仮想オブジェクトを呼び出すときにNULL nullオブジェクトに 'java.lang.String android.net.Uri.getPath()'メソッドがあります in.esla.rwss_customer.ImageCompress.scal in.esla.rwss_customer.WaterFragmentNew.dealTakePhoto(WaterFragmentNew.java:368)で(ImageCompress.java:28) をATで in.esla.rwss_customer.WaterFragmentNew.onActivityResult android.app.Activity.dispatchActivityResultで android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:165) で(WaterFragmentNew.java:350) (活動。 Javaの:6508 android.app.ActivityThread.deliverResultsで) (ActivityThread.java:3738) でandroid.app.ActivityThread.performResumeActivity(ActivityThread.java:3122) でandroid.app.ActivityThread.handleResumeActivity(ActivityThread。 java:3167) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2514) android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1373)android.os.Handler.dispatchMessageで (Handler.javaでandroid.app.ActivityThread.access $ 1000(ActivityThread.java:153) で : 10235) android.os.Looper.loop(Looper.java:154) とandroid.app.ActivityThread.main(ActivityThread.java:5527) at java.lang.reflect.Method.invoke(ネイティブメソッド) atcom.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:738) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)05-11 10:40:23.608 864-864/in.esla.rwss_customer E/MQSEventManagerDelegate: MQSServiceの取得に失敗しました。

+0

> 23でテストしている場合は動作しません。 23歳未満でテストしてください、それが動作するかどうかを私に教えてください。次に私は> 23 –

+0

のためにあなたに解決策を提供します23以下の問題は特にこの問題はredmi note3のみで発生します。残りの携帯電話は正常に動作します。 –

答えて