I started creating Watch Face for Android Wear. I have implemented almost everything, and now I want to show the phoneβs battery on my face. From what I understood after my research, this can only be done through the message or data API. Therefore, I began to work in my field, but in the face of problems at the very beginning. I cannot connect to the Google Api client.
I have two classes for "wear and tear" - one common for watches (services) and one created by me:
public class BatteryActivity extends Activity { GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks( new ConnectionCallbacks() { @Override public void onConnected(Bundle connectionHint) { Log.i( "", "onConnected: " + connectionHint);
What I just repeat like this: BatteryActivity batteryActivity = new BatteryActivity(); I get this error:
java.lang.NullPointerException: attempt to call the virtual method 'android.os.Looper android.content.Context.getMainLooper ()' at zero object reference
I do not understand how mGoogleApiClient is null if I instantiate it. As a side note - this is purely based on Google documentation here - https://developer.android.com/training/wearables/data-layer/messages.html
source share