我在Android Studio中构建项目时没有任何问题,但是当我在设备中运行该项目时,它崩溃了,而且我看不到任何错误报告来了解正在发生的事情。
我使用此行来调用方法:
Bitmap res = imageopsRS.bmpresize(rs,mBitmap,200,500);
方法是:
public class imageopsRS {
public static Bitmap bmpresize(RenderScript rs, Bitmap src, int destW, int destH) {
Bitmap.Config bmpCfg = src.getConfig();
Allocation tmp = Allocation.createFromBitmap(rs, src);
Allocation tmpType = Allocation.createTyped(rs, tmp.getType());
tmp.destroy();
Bitmap dst = Bitmap.createBitmap(destW, destH, bmpCfg);
Type t = Type.createXY(rs, tmpType.getElement(), destW, destH);
Allocation tmpO = Allocation.createTyped(rs, t);
ScriptIntrinsicResize rsIntr = ScriptIntrinsicResize.create(rs);
rsIntr.setInput(tmpType);
rsIntr.forEach_bicubic(tmpO);
tmpO.copyTo(dst);
tmpType.destroy();
tmpO.destroy();
rsIntr.destroy();
return dst;
}
整个项目都在这里: https://github.com/youyeg/resizeRS
08-07 15:58:25.376 10478-10478/com.yousef.imageresizer E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.yousef.imageresizer, PID: 10478
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
at android.view.View.performClick(View.java:6261)
at android.widget.TextView.performClick(TextView.java:11159)
at android.view.View$PerformClick.run(View.java:23748)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:6261)
at android.widget.TextView.performClick(TextView.java:11159)
at android.view.View$PerformClick.run(View.java:23748)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Bitmap$Config android.graphics.Bitmap.getConfig()' on a null object reference
at com.yousef.imageresizer.imageopsRS.bmpresize(imageopsRS.java:9)
at com.yousef.imageresizer.MainActivity.onButtonMethodOneClicked(MainActivity.java:67)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:6261)
at android.widget.TextView.performClick(TextView.java:11159)
at android.view.View$PerformClick.run(View.java:23748)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)