android - findViewById() returns null in OnLayoutInflatedListener -


i've adapted default code reference circledimageview can set it's background color, returns null. i've tried setting src / background in xml file view, neither worked. returned errors, trying inflate view.

edit: think problem might circledimageview - has used successfully?

public class myactivity  extends activity {  private circledimageview mcircle;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_my);     final watchviewstub stub = (watchviewstub) findviewbyid(r.id.watch_view_stub);     stub.setonlayoutinflatedlistener(new watchviewstub.onlayoutinflatedlistener() {         @override         public void onlayoutinflated(watchviewstub stub) {             mcircle = (circledimageview) stub.findviewbyid(r.id.circle);             mcircle.setcirclecolor(color.red);         }     }); } } 

here watch-view-stub xml code

<?xml version="1.0" encoding="utf-8"?> <android.support.wearable.view.watchviewstub     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/watch_view_stub"     android:layout_width="match_parent"     android:layout_height="match_parent"     app:rectlayout="@layout/rect_activity_my"     app:roundlayout="@layout/round_activity_my"     tools:context="com.larvalabs.weartest.myactivity"     tools:deviceids="wear"> </android.support.wearable.view.watchviewstub> 

it returns following error

06-27 15:49:14.262    1679-1679/com.larvalabs.weartest e/androidruntime﹕ fatal exception: main process: com.larvalabs.weartest, pid: 1679 java.lang.nullpointerexception         @ com.larvalabs.weartest.myactivity$1.onlayoutinflated(myactivity.java:25)         @ android.support.wearable.view.watchviewstub.inflate(watchviewstub.java:133)         @ android.support.wearable.view.watchviewstub.onmeasure(watchviewstub.java:141)         @ android.view.view.measure(view.java:16648)         @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125)         @ android.widget.framelayout.onmeasure(framelayout.java:310)         @ android.view.view.measure(view.java:16648)         @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125)         @ android.widget.framelayout.onmeasure(framelayout.java:310)         @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2321)         @ android.view.view.measure(view.java:16648)         @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:1959)         @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1145)         @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1340)         @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1032)         @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5657)         @ android.view.choreographer$callbackrecord.run(choreographer.java:761)         @ android.view.choreographer.docallbacks(choreographer.java:574)         @ android.view.choreographer.doframe(choreographer.java:544)         @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:747)         @ android.os.handler.handlecallback(handler.java:733)         @ android.os.handler.dispatchmessage(handler.java:95)         @ android.os.looper.loop(looper.java:136)         @ android.app.activitythread.main(activitythread.java:5026)         @ java.lang.reflect.method.invokenative(native method)         @ java.lang.reflect.method.invoke(method.java:515)         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:777)         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:602)         @ dalvik.system.nativestart.main(native method) 

do setcontentview in onreadyforcontent instead of oncreate , should good.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -