2017-08-16 188 views
1

我一直在使用库com.theartofdev.edmodo:android-image-cropper:2.4。+进行图像裁剪。在这里,我遇到了一个问题,当我能够打开我的画廊,但是当我选择一个图像裁剪我的应用程序崩溃。 08-16 16:52:14.661 30951-909/com.myproj.blogapp E/AndroidRuntime:致命异常:#的AsyncTask 1 过程:致命异常:AsyncTask#1裁剪图像

com.myproj.blogapp, PID: 30951 
                    java.lang.RuntimeException: An error occured while executing doInBackground() 
                     at android.os.AsyncTask$3.done(AsyncTask.java:300) 
                     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) 
                     at java.util.concurrent.FutureTask.setException(FutureTask.java:222) 
                     at java.util.concurrent.FutureTask.run(FutureTask.java:242) 
                     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                     at java.lang.Thread.run(Thread.java:818) 
                    Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/media/ExifInterface; 
                     at com.theartofdev.edmodo.cropper.BitmapUtils.rotateBitmapByExif(BitmapUtils.java:85) 
                     at com.theartofdev.edmodo.cropper.BitmapLoadingWorkerTask.doInBackground(BitmapLoadingWorkerTask.java:92) 
                     at com.theartofdev.edmodo.cropper.BitmapLoadingWorkerTask.doInBackground(BitmapLoadingWorkerTask.java:26) 
                     at android.os.AsyncTask$2.call(AsyncTask.java:288) 
                     at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)  
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)  
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)  
                     at java.lang.Thread.run(Thread.java:818)  
                    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.media.ExifInterface" on path: DexPathList[[zip file "/data/app/com.myproj.blogapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
                     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
                     at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
                     at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 
                     at com.theartofdev.edmodo.cropper.BitmapUtils.rotateBitmapByExif(BitmapUtils.java:85)  
                     at com.theartofdev.edmodo.cropper.BitmapLoadingWorkerTask.doInBackground(BitmapLoadingWorkerTask.java:92)  
                     at com.theartofdev.edmodo.cropper.BitmapLoadingWorkerTask.doInBackground(BitmapLoadingWorkerTask.java:26)  
                     at android.os.AsyncTask$2.call(AsyncTask.java:288)  
                     at java.util.concurrent.FutureTask.run(FutureTask.java:237)  
                     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)  
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)  
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)  
                     at java.lang.Thread.run(Thread.java:818)  
                    Suppressed: java.lang.ClassNotFoundException: android.support.media.ExifInterface 
                     at java.lang.Class.classForName(Native Method) 
                     at java.lang.BootClassLoader.findClass(ClassLoader.java:781) 
                     at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 
                     at java.lang.ClassLoader.loadClass(ClassLoader.java:504) 
                      ... 10 more 
                    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

的Java

package com.myproj.blogapp; 

import android.content.Intent; 
import android.net.Uri; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ImageButton; 

import com.theartofdev.edmodo.cropper.CropImage; 
import com.theartofdev.edmodo.cropper.CropImageView; 

import org.w3c.dom.Text; 

public class SetupActivity extends AppCompatActivity { 

    private ImageButton mSetupImageBtn; 
    private EditText mNameField; 
    private Button mSubmitBtn; 

    private static final int GALLERY_REQUEST = 1; 



    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_setup); 

     mSetupImageBtn = (ImageButton) findViewById(R.id.setupImageBtn); 
     mNameField = (EditText) findViewById(R.id.nameField); 
     mSubmitBtn = (Button) findViewById(R.id.submitBtn); 

     mSetupImageBtn.setOnClickListener(new View.OnClickListener(){ 
      @Override 
      public void onClick(View view) { 
       Intent galleryIntent = new Intent(); 
       galleryIntent.setAction(Intent.ACTION_GET_CONTENT); 
       galleryIntent.setType("image/*"); 
       startActivityForResult(galleryIntent, GALLERY_REQUEST); 
      } 
     }); 

    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if(requestCode == GALLERY_REQUEST && resultCode == RESULT_OK){ 
      Uri imageUri = data.getData(); 

      CropImage.activity(imageUri) 
        .setGuidelines(CropImageView.Guidelines.ON) 
        .setAspectRatio(1,1) 
        .start(this); 
     } 

     if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { 
      CropImage.ActivityResult result = CropImage.getActivityResult(data); 


      if (resultCode == RESULT_OK) { 
       Uri resultUri = result.getUri(); 

       mSetupImageBtn.setImageURI(resultUri); 

      } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { 
       Exception error = result.getError(); 
      } 
     } 
    } 
} 
+0

你使用multidex? –

+0

是啊它启用 –

+0

啊今天是美好的一天。谢谢! –

回答

2

添加到您的应用build.gradle依赖关系

compile 'com.android.support:exifinterface:26.+' 

请注意compileSdkVersion。我使用26,这就是为什么我有'26。+'