2014-09-24 26 views
0

在這裏,我再次遇到來自ABBYY SDK的另一個問題。ABBYY移動圖像SDK,Nullpointer @OnImageOperationSelected

我已經完成了用這個SDK加載圖像,現在我想要做一個ImageOperation。但是我得到一個空指針異常。

錯誤日誌:

09-24 10:27:56.170 3560-3560/com.example.docsproscan E/AndroidRuntime﹕ FATAL EXCEPTION: main 
java.lang.NullPointerException 
     at com.example.docsproscan.EditPhoto.addWidgets(EditPhoto.java:316) 
     at com.example.docsproscan.EditPhoto.onImageOperationSelected(EditPhoto.java:311) 
     at com.example.docsproscan.EditPhoto.access$100(EditPhoto.java:60) 
     at com.example.docsproscan.EditPhoto$3.onClick(EditPhoto.java:147) 
     at android.view.View.performClick(View.java:4240) 
     at android.view.View$PerformClick.run(View.java:17721) 
     at android.os.Handler.handleCallback(Handler.java:730) 
     at android.os.Handler.dispatchMessage(Handler.java:92) 
     at android.os.Looper.loop(Looper.java:137) 
     at android.app.ActivityThread.main(ActivityThread.java:5103) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:525) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
     at dalvik.system.NativeStart.main(Native Method) 

CODE:

snijden.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      /*bitmapHeight = resized.getHeight(); 
      bitmapWidth = resized.getWidth(); 

      ratioWidth = (double) imageViewWidth/(double) bitmapWidth; 
      ratioHeight = (double) imageViewHeight/(double) bitmapHeight; 
      Bitmap bitmap = crop.crop(resized, ratioWidth, ratioHeight); 
      imageView.setImageBitmap(bitmap); 
      imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 
      */ 
      Log.d("mainactivity", "" + operations.get(2)); 

      Log.d("operation controller", "" + new ControllerToGreyscale() + " something"); 
      onImageOperationSelected(operations.get(2)); 
     } 
    }); 

private void onImageOperationSelected(final ImageOperation imageOperation) { 
    Log.d("MainActivity", "onImageOperationSelected()"); 
    if(imageOperation != _imageOperation) { 
     _needUpdateSource = true; 
    } 
    _imageOperation = imageOperation; 
    _operationController = imageOperation.getController(); 
    addWidgets(_operationController); 
    _operationController.setResultView(_imageView, IN_SAMPLE_SIZE); 
} 

private void addWidgets(final OperationController operationController) { 
    _controlsContainer.removeAllViews(); 
    final List<ParametrControl> controls = operationController.createControls(this); 
    for(final ParametrControl control : controls) { 
     _controlsContainer.addView(control.getView()); 
    } 
} 

這裏的問題是,它說,它沒有ImageOperation價值。然而,示例應用程序(隨SDK提供)傳遞與我的應用程序相同的值。但在我的應用程序中,它提供了一個空指針並在它運行的示例應用程序上。

任何人都知道如何解決這個零點問題?

-

上面的代碼是使用這個SDK需要無盡類只是一個小片段。

ImageOperation類。

public enum ImageOperation implements LabeledColoredItem { 
AUTO_BRIGHTNESS_CONTRAST(R.string.auto_brightness_contrast, new ControllerAutoBrightnessContrast(), 
     OperationType.FILTER), 
AUTO_ENHANCE(R.string.auto_enhance, new ControllerAutoEnhance(), OperationType.FILTER), 
CONVERT_TO_GREYSCALE(R.string.convert_to_greyscale, new ControllerToGreyscale(), OperationType.FILTER), 
//CROP(R.string.crop, new ControllerCrop(), OperationType.FILTER), 
RECOGNIZE_EDGES(R.string.recognize_edges, new ControllerRecognizeEdges(), OperationType.DETECT); 

/** Text resource's ID representing the name of the operation */ 
private final int _labelResourceId; 

private OperationController _controller; 

private OperationType _type; 

/** 
* @param labelResourceId 
*   text resource's ID representing the name of the operation 
* @param control 
* @param type 
*   operation type: filter/detector/preset 
*/ 
private ImageOperation(final int labelResourceId, final OperationController control, 
     final OperationType type) { 
    _labelResourceId = labelResourceId; 
    _controller = control; 
    _type = type; 
} 

public OperationController getController() { 
    return _controller; 
} 

@Override 
public String getLabel(final Context context) { 
    return context.getString(_labelResourceId); 
} 

public OperationType getType() { 
    return _type; 
} 

public static enum OperationType { 
    FILTER, 
    DETECT, 
    PRESET; 
} 

@Override 
public int getColor(final Context context) { 
    switch(_type) { 
     case DETECT: 
      return context.getResources().getColor(R.color.detectorColor); 
     case FILTER: 
      return context.getResources().getColor(R.color.filterColor); 
     case PRESET: 
      return context.getResources().getColor(R.color.presetColor); 
     default: 
      return -1; 
    } 
} 

/** 
* Comparator to sort values of {@link com.example.wp08_gillz.abbyy.com.ABBY.ImageOperation}. 
* Filter operations comes first, then detectors, then presets. Inside the group - by alphabetical order. 
*/ 
public static class ImageOperationComparator implements Comparator<ImageOperation> { 
    private final Context _context; 

    public ImageOperationComparator(final Context context) { 
     _context = context; 
    } 

    @Override 
    public int compare(final ImageOperation first, final ImageOperation second) { 
     if(first._type.ordinal() < second._type.ordinal()) { 
      return -1; 
     } 
     if(first._type.ordinal() > second._type.ordinal()) { 
      return 1; 
     } 
     return first.getLabel(_context).compareTo(second.getLabel(_context)); 
    } 
} 

的Log.d的操作的值的結果[2]:

10月9日至24日:27:56.162 3560-3560/com.example.docsproscan d/mainactivity:CONVERT_TO_GREYSCALE

回答

0

已解決。添加小部件會導致erorr。然而,我們可能不需要這種方法,所以在哪裏調試一些更遠,並刪除我們的應用程序的方法。

+0

只是一個未來的提示:使用http://forum.ocrsdk.com聯繫ABBYY支持團隊 – 2014-09-25 11:07:44

+0

我會牢記這一點,謝謝:) – 2014-09-25 11:17:01