此处我再次提到ABBYY SDK中的另一个问题。
我已经完成了使用此SDK加载图像,现在我想进行ImageOperation。但是我得到了一个nullpointer异常。
错误日志:
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)
代码:
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附带)传递的值与我的应用程序相同。但是在我的应用程序上,它会提供一个nullpointer,并在它运行的示例应用程序上运行。
任何人都知道如何解决这个nullpointer问题?
-
以上代码只是使用此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 ) );
}
}
操作值[2]的Log.d的结果:
09-24 10:27:56.162 3560-3560 / com.example.docsproscan D / mainactivity:CONVERT_TO_GREYSCALE
答案 0 :(得分:0)
解决。添加小部件会导致错误。但是我们可能不需要这个方法,所以要调试更远的地方并从我们的应用程序中删除方法。