0

Here I am again with another problem from the ABBYY SDK.

I've accomplished to load the image with this SDK, now I want to do a ImageOperation. However im getting a nullpointer exception.

Error LOG:

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() );
    }
}

The issue here is that it says it has no ImageOperation value. However the sample app (comes with the SDK) passes the same value as my app. But on my app it gives a nullpointer and on the sample app it runs.

Anyone know how to solve this nullpointer problem?

-

The above code is just a small snippet of the endless classes needed to use this SDK.

ImageOperation class.

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 ) );
    }
}

The result of the Log.d for the value of operation[2] :

09-24 10:27:56.162 3560-3560/com.example.docsproscan D/mainactivity﹕ CONVERT_TO_GREYSCALE

4

1 回答 1

0

解决了。添加小部件导致错误。但是,我们可能不需要该方法,因此要进一步调试并从我们的应用程序中删除该方法。

于 2014-09-24T09:45:43.823 回答