0

I'm totally new in the developer world, i started coding just 2 days ago, but until now everything went well.

Now i'm trying to make an android watchface and i'm trying to display just a basic bitmap on the smartwatch (using emulator)

The problem is that my watchface just crashes and the logcat says this:

06-29 17:35:58.182 5594-5594/wear.trombettonj.prova2 E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   Process: wear.trombettonj.prova2, PID: 5594
                                                                   java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
                                                                       at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:658)
                                                                       at wear.trombettonj.prova2.AnalogWatchface$Engine.onSurfaceChanged(AnalogWatchface.java:126)
                                                                       at android.service.wallpaper.WallpaperService$Engine.updateSurface(WallpaperService.java:770)
                                                                       at android.service.wallpaper.WallpaperService$Engine.attach(WallpaperService.java:878)
                                                                       at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:1165)
                                                                       at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                       at android.os.Looper.loop(Looper.java:154)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5974)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:801)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)

I tried fixing those errors and for example if i click on WallpaperService.java:770 it brings me to this file.

This file i assume is a primitive java library since it has not be created by me, and this file is FULL of errors "cannot resolve symbol 'PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS (example)'"

What is the problem here?

lugiank
  • 71
  • 8

1 Answers1

0

The important parts of the stack trace are:

Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference

and

at wear.trombettonj.prova2.AnalogWatchface$Engine.onSurfaceChanged(AnalogWatchface.java:126)

meaning that at line 126 of your AnalogWatchface class, your're calling getWidth() on a null Bitmap object. It's nothing to do with WallpaperService per se.

Sterling
  • 6,365
  • 2
  • 32
  • 40