codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.

Home Page:https://www.codenameone.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NullPointerException while using the camera in the simulator

Yberamos opened this issue · comments

Describe the bug
Scaling an image in the simulator throw an NullPointerException, even if not scaling it explicitly with a scaledWidth/Height. But works fine when running on Android or iOS.

java.lang.NullPointerException
at com.codename1.impl.javase.JavaSEPort.scale(JavaSEPort.java:5804)
at com.codename1.ui.Image.scale(Image.java:1028)
at com.codename1.ui.Image.scaledImpl(Image.java:974)
at com.codename1.ui.Image.scaled(Image.java:939)
at com.codename1.ui.Image.scaledWidth(Image.java:878)
at com.codename1.demos.kitchen.MediaDemo.lambda$createContentPane$8(MediaDemo.java:157)
at com.codename1.impl.javase.JavaSEPort$77$1.run(JavaSEPort.java:10059)
at com.codename1.ui.Display.processSerialCalls(Display.java:1338)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1280)
at com.codename1.ui.Display.mainEDTLoop(Display.java:1162)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

To Reproduce
I've created a fork of KitchenSink (https://github.com/Yberamos/KitchenSinkPicture ). To replicate the bug:

  1. Go in Media
  2. Choose either "Take image" or "Take image (scale)"

Expected behavior
A Toast show up with the path of the image

Desktop (please complete the following information):

  • OS: Windows 11

This stack trace is from an older version of Codename One so the line numbers don't map to the right places.

I noticed in the sample that you don't check if the image was loaded correctly, if the image loading failed this could cause a problem.

FYI img.scaledWidth((int) (100 * 0.4)); is incorrect since it will return a new image instance it should be img = img.scaledWidth((int) (100 * 0.4));