Search code examples
codenameone

CN1 CameraKit gives null PeerComponent


I'm trying the default code in the Readme of the CameraKit CN1Lib on a new bare bones project: https://github.com/codenameone/CameraKitCodenameOne

It works in the simulator with the webcam, but on a real Android device the line hi.add(ck.getView()); throws an exception because of a null object reference.

I suspect that the problem is that the camera permissions are not asked.

However, in the codenameone_settings.properties, there is the line:

codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.CAMERA" required\="true"/><uses-permission android\:name\="android.permission.RECORD_AUDIO" required\="true"/>

so I don't know how to solve this issue.

This don't seem related to the new Android API, because the issue exists also with:

codename1.arg.android.targetSDKVersion=28
codename1.arg.android.buildToolsVersion=28

Solution

  • The solution is the use of ck.start(); and ck.stop();, as in this example: https://github.com/codenameone/CameraKitCodenameOne/blob/master/CameraKitDemo/src/com/codename1/camerakit/demo/CameraKitDemo.java

    Without ck.start();, ck.getView() returns null.

    So the example in the ReadMe is not usable as it is, because it doesn't invoke ck.start(); neither ck.stop();