Skip to content

Instantly share code, notes, and snippets.

@MaciejCiemiega
Last active August 29, 2015 14:03
Show Gist options
  • Save MaciejCiemiega/8dbcf9e5ce22757c3549 to your computer and use it in GitHub Desktop.
Save MaciejCiemiega/8dbcf9e5ce22757c3549 to your computer and use it in GitHub Desktop.
WearableListView NullpointerException...
NOTE: After clicking on the top part of the screen (empty space above "Item 0"):
java.lang.NullPointerException
at android.support.wearable.view.WearableListView.checkForTap(WearableListView.java:283)
at android.support.wearable.view.WearableListView.handleTouchUp(WearableListView.java:404)
at android.support.wearable.view.WearableListView.onTouchEvent(WearableListView.java:199)
at android.view.View.dispatchTouchEvent(View.java:7846)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1944)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2215)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1958)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2215)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1958)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2085)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1532)
at android.app.Activity.dispatchTouchEvent(Activity.java:2468)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2033)
at android.view.View.dispatchPointerEvent(View.java:8026)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3989)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3868)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3433)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3483)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3559)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3460)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3616)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3433)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3483)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3460)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3433)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5589)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5569)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5540)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5669)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:5026)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
import android.app.Activity;
import android.os.Bundle;
import android.support.wearable.view.WearableListView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class WearableListViewActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final WearableListView wearableListView = new WearableListView(this);
wearableListView.setAdapter(new WearableListAdapter());
setContentView(wearableListView);
}
public class WearableListAdapter extends WearableListView.Adapter {
private final String[] items = { "Item 0", "Item 1", "Item 2" };
@Override
public int getItemCount() {
return items.length;
}
@Override
public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final View view = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
return new WearableListView.ViewHolder(view);
}
@Override
public void onBindViewHolder(WearableListView.ViewHolder viewHolder, int position) {
((TextView)viewHolder.itemView).setText(items[position]);
}
}
}
@MaciejCiemiega
Copy link
Author

Solution to this problem: just set empty ClickListener. Without setting one WearableListView will throw NullPointerException when clicking on top empty space:\

wearableListView.setClickListener(new ClickListener() {
    @Override
    public void onTopEmptyRegionClick() {
    }

    @Override
    public void onClick(ViewHolder arg0) {
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment