this android activity is not working -
this code not working since have added showpopup() method, couldn't figure out reason. whats problem in code?
package com.example.healthcity.activities; import org.taptwo.android.widget.circleflowindicator; import org.taptwo.android.widget.viewflow; import com.example.healthcity.r; import com.example.healthcity.dataobjs.demodataadapter; import android.app.activity; import android.content.context; import android.os.bundle; import android.os.handler; import android.view.gravity; import android.view.layoutinflater; import android.view.view; import android.widget.framelayout; import android.widget.linearlayout; import android.widget.popupwindow; public class demoviewflowactivity extends activity { private viewflow viewflow; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.bf_home_screen); // viewflow = (viewflow) findviewbyid(r.id.viewflow); // viewflow.setadapter(new demodataadapter(this)); // circleflowindicator indic = (circleflowindicator) // findviewbyid(r.id.viewflowindic); // viewflow.setflowindicator(indic); } @override protected void onstart() { super.onstart(); showpopup(demoviewflowactivity.this); } // method displays popup. private void showpopup(activity context) { int popupwidth = 200; int popupheight = 150; // inflate popup_layout.xml framelayout viewgroup = (framelayout) context.findviewbyid(r.id.popup); layoutinflater layoutinflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); view layout = layoutinflater.inflate(r.layout.circle_layout, viewgroup); // creating popupwindow popupwindow popup = new popupwindow(context); popup.setcontentview(layout); popup.setwidth(popupwidth); popup.setheight(popupheight); popup.setfocusable(true); // offset align popup bit right, , bit down, // relative button's position. int offset_x = 30; int offset_y = 30; // displaying popup @ specified location, + offsets. popup.showatlocation(layout, gravity.no_gravity, 50, 50); viewflow = (viewflow) findviewbyid(r.id.viewflow); viewflow.setadapter(new demodataadapter(this)); circleflowindicator indic = (circleflowindicator) findviewbyid(r.id.viewflowindic); viewflow.setflowindicator(indic); // getting reference close button, , close popup when // clicked. // button close = (button) layout.findviewbyid(r.id.close); // close.setonclicklistener(new onclicklistener() { // // @override // public void onclick(view v) { // popup.dismiss(); // } // }); } }
here part of logcat error seem appear:
07-23 23:34:25.960: w/dalvikvm(4048): threadid=1: thread exiting uncaught exception (group=0x40a71930) 07-23 23:34:25.969: e/androidruntime(4048): fatal exception: main 07-23 23:34:25.969: e/androidruntime(4048): java.lang.runtimeexception: unable start activity componentinfo{com.example.healthcity/com.example.healthcity.activities.demoviewflowactivity}: android.view.windowmanager$badtokenexception: unable add window -- token null not valid; activity running? 07-23 23:34:25.969: e/androidruntime(4048): @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 07-23 23:34:25.969: e/androidruntime(4048): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 07-23 23:34:25.969: e/androidruntime(4048): @ android.app.activitythread.access$600(activitythread.java:141) 07-23 23:34:25.969: e/androidruntime(4048): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 07-23 23:34:25.969: e/androidruntime(4048): @ android.os.handler.dispatchmessage(handler.java:99) 07-23 23:34:25.969: e/androidruntime(4048): @ android.os.looper.loop(looper.java:137) 07-23 23:34:25.969: e/androidruntime(4048): @ android.app.activitythread.main(activitythread.java:5041) 07-23 23:34:25.969: e/androidruntime(4048): @ java.lang.reflect.method.invokenative(native method) 07-23 23:34:25.969: e/androidruntime(4048): @ java.lang.reflect.method.invoke(method.java:511) 07-23 23:34:25.969: e/androidruntime(4048): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 07-23 23:34:25.969: e/androidruntime(4048): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 07-23 23:34:25.969: e/androidruntime(4048): @ dalvik.system.nativestart.main(native method) 07-23 23:34:25.969: e/androidruntime(4048): caused by: android.view.windowmanager$badtokenexception: unable add window -- token null not valid; activity running? 07-23 23:34:25.969: e/androidruntime(4048): @ android.view.viewrootimpl.setview(viewrootimpl.java:567) 07-23 23:34:25.969: e/androidruntime(4048): @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:246) 07-23 23:34:25.969: e/androidruntime(4048): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) 07-23 23:34:25.969: e/androidruntime(4048): @ android.widget.popupwindow.invokepopup(popupwindow.java:993) 07-23 23:34:25.969: e/androidruntime(4048): @ android.widget.popupwindow.showatlocation(popupwindow.java:847) 07-23 23:34:25.969: e/androidruntime(4048): @ android.widget.popupwindow.showatlocation(popupwindow.java:811) 07-23 23:34:25.969: e/androidruntime(4048): @ com.example.healthcity.activities.demoviewflowactivity.showpopup(demoviewflowactivity.java:81) 07-23 23:34:25.969: e/androidruntime(4048): @ com.example.healthcity.activities.demoviewflowactivity.onstart(demoviewflowactivity.java:54) 07-23 23:34:25.969: e/androidruntime(4048): @ android.app.instrumentation.callactivityonstart(instrumentation.java:1164) 07-23 23:34:25.969: e/androidruntime(4048): @ android.app.activity.performstart(activity.java:5114) 07-23 23:34:25.969: e/androidruntime(4048): @ android.app.activitythread.performlaunchactivity(activitythread.java:2153)
change code this:
replace call showpopup(this)
with:
new handler().postdelayed(new runnable() { public void run() { showpopup(demoviewflowactivity.this); } }, 100l);
edit 1:
usually, 100 milliseconds delay works wonders in kind of situation. but, seeing getting exception after using 1 second delay, tried following:
i made simple layout file(say, r.layout.simple_layout) containing linearlayout
. not matter layout is. gave id
(say, @+id/llempty). now, in oncreate(bundle), set layout using setcontentview(r.layout.simple_layout)
. and, in onstart()
, put following:
@override protected void onstart() { super.onstart(); findviewbyid(r.id.llempty).post(new runnable() { @override public void run() { // method creates , displays popup showlist(); } }); }
how translate code:
your layout file r.layout.bf_home_screen
contains relativelayout
or linearlayout
parent layout. give parent layout id
using android:id="@+id/some_id"
. change onstart()
method to:
@override protected void onstart() { super.onstart(); // replace "some_id" id use in layout file findviewbyid(r.id.some_id).post(new runnable() { @override public void run() { showpopup(demoviewflowactivity.this); } }); }
Comments
Post a Comment