开发者

How to save paint file?

开发者 https://www.devze.com 2023-03-04 08:21 出处:网络
I have a paint program that has no save function. I want to know if I can get this code to work? // TODO Auto-generated method stub

I have a paint program that has no save function. I want to know if I can get this code to work?

// TODO Auto-generated method stub
       OutputStream outStream = null;
       File file = new File(extStorageDirectory, "000.PNG");
       try {
        outStream = new FileOutputStream(file);
        mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
        outStream.flush();
        outStream.close();

        Toast.makeText(ThePatch.this, "Saved", Toast.LENGTH_LONG).show();

       } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Toast.makeText(ThePatch.this, e.toString(), Toast.LENGTH_LONG).show();
       } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Toast.makeText(ThePatch.this, e.toString(), Toast.LENGTH_LONG).show();
       }

      }

It saves a file but just shows a black screen. and I get a FC on line 237 according to the log cat.

Line 237

            mBitmap.compress(Bi开发者_JS百科tmap.CompressFormat.JPEG, 100, outStream);

Logcat

05-09 21:19:10.405: ERROR/AndroidRuntime(11437): FATAL EXCEPTION: main
05-09 21:19:10.405: ERROR/AndroidRuntime(11437): java.lang.NullPointerException
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at www.hotapp.com.thepatch.html.ThePatch.onOptionsItemSelected(ThePatch.java:237)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at android.app.Activity.onMenuItemSelected(Activity.java:2195)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at android.view.View$PerformClick.run(View.java:8816)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at android.os.Handler.handleCallback(Handler.java:587)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at android.os.Looper.loop(Looper.java:123)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at java.lang.reflect.Method.invokeNative(Native Method)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at java.lang.reflect.Method.invoke(Method.java:521)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at dalvik.system.NativeStart.main(Native Method)

here is my onDraw

@Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(0xFFAAAAAA);

        canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

        canvas.drawPath(mPath, mPaint);
    }

I took the code from here.


So your code is trying to access a null pointer here:

05-09 21:19:10.405: ERROR/AndroidRuntime(11437): java.lang.NullPointerException
05-09 21:19:10.405: ERROR/AndroidRuntime(11437):     at www.hotapp.com.thepatch.html.ThePatch.onOptionsItemSelected(ThePatch.java:237)

Fix that.

0

精彩评论

暂无评论...
验证码 换一张
取 消