Why does my app force close on moving from one fragment to another on a ImageView click in Android? -
i trying move mycontacts extends fragment
tasks extends fragment
on clicking imageview
. imageview in listview
generated using simpleadapter
.the ids of layouts follows:r.id.tasky
tasks fragment,r.id.mycontacts
mycontacts fragment. codes , error logs follows. new fragments kindly explain me step step.
mycontacts extends fragment
purple.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub android.app.fragmenttransaction t = getactivity().getfragmentmanager().begintransaction(); fragment fragment = new tasks(); fragmentmanager fragmentmanager = getactivity().getsupportfragmentmanager(); fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); fragmenttransaction.replace(r.id.tasky, fragment); fragmenttransaction.addtobackstack(null); fragmenttransaction.commit(); } });
error logs:
04-22 04:41:52.486: e/fragmentmanager(3250): no view found id 0x7f04004f (com.example.taskmanager:id/tasky) fragment tasks{b4ee0f70 #1 id=0x7f04004f} 04-22 04:41:52.486: e/fragmentmanager(3250): activity state: 04-22 04:41:53.626: e/androidruntime(3250): fatal exception: main 04-22 04:41:53.626: e/androidruntime(3250): process: com.example.taskmanager, pid: 3250 04-22 04:41:53.626: e/androidruntime(3250): java.lang.illegalargumentexception: no view found id 0x7f04004f (com.example.taskmanager:id/tasky) fragment tasks{b4ee0f70 #1 id=0x7f04004f} 04-22 04:41:53.626: e/androidruntime(3250): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:919) 04-22 04:41:53.626: e/androidruntime(3250): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1104) 04-22 04:41:53.626: e/androidruntime(3250): @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682) 04-22 04:41:53.626: e/androidruntime(3250): @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1467) 04-22 04:41:53.626: e/androidruntime(3250): @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:440) 04-22 04:41:53.626: e/androidruntime(3250): @ android.os.handler.handlecallback(handler.java:733) 04-22 04:41:53.626: e/androidruntime(3250): @ android.os.handler.dispatchmessage(handler.java:95) 04-22 04:41:53.626: e/androidruntime(3250): @ android.os.looper.loop(looper.java:136) 04-22 04:41:53.626: e/androidruntime(3250): @ android.app.activitythread.main(activitythread.java:5017) 04-22 04:41:53.626: e/androidruntime(3250): @ java.lang.reflect.method.invokenative(native method) 04-22 04:41:53.626: e/androidruntime(3250): @ java.lang.reflect.method.invoke(method.java:515) 04-22 04:41:53.626: e/androidruntime(3250): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 04-22 04:41:53.626: e/androidruntime(3250): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 04-22 04:41:53.626: e/androidruntime(3250): @ dalvik.system.nativestart.main(native method) 04-22 04:45:17.276: e/fragmentmanager(3351): no view found id 0x7f04004f (com.example.taskmanager:id/tasky) fragment tasks{b4ef7ac0 #1 id=0x7f04004f} 04-22 04:45:17.276: e/fragmentmanager(3351): activity state: 04-22 04:45:18.476: e/androidruntime(3351): fatal exception: main 04-22 04:45:18.476: e/androidruntime(3351): process: com.example.taskmanager, pid: 3351 04-22 04:45:18.476: e/androidruntime(3351): java.lang.illegalargumentexception: no view found id 0x7f04004f (com.example.taskmanager:id/tasky) fragment tasks{b4ef7ac0 #1 id=0x7f04004f} 04-22 04:45:18.476: e/androidruntime(3351): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:919) 04-22 04:45:18.476: e/androidruntime(3351): @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1104) 04-22 04:45:18.476: e/androidruntime(3351): @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682) 04-22 04:45:18.476: e/androidruntime(3351): @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1467) 04-22 04:45:18.476: e/androidruntime(3351): @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:440) 04-22 04:45:18.476: e/androidruntime(3351): @ android.os.handler.handlecallback(handler.java:733) 04-22 04:45:18.476: e/androidruntime(3351): @ android.os.handler.dispatchmessage(handler.java:95) 04-22 04:45:18.476: e/androidruntime(3351): @ android.os.looper.loop(looper.java:136) 04-22 04:45:18.476: e/androidruntime(3351): @ android.app.activitythread.main(activitythread.java:5017) 04-22 04:45:18.476: e/androidruntime(3351): @ java.lang.reflect.method.invokenative(native method) 04-22 04:45:18.476: e/androidruntime(3351): @ java.lang.reflect.method.invoke(method.java:515) 04-22 04:45:18.476: e/androidruntime(3351): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 04-22 04:45:18.476: e/androidruntime(3351): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 04-22 04:45:18.476: e/androidruntime(3351): @ dalvik.system.nativestart.main(native method)
your mycontacts fragment
xml not have viewgroup
id r.id.tasky
. can use interface call activity , replace existing fragment in container another.
you can find code snippets @
http://developer.android.com/training/basics/fragments/communicating.html
in example in docs there listfragment
on listitemclick
communicate value activity
. in activity replace existing fragment new 1 , communicate value same.
similarly on imageview
click communicate activity activity replace appropriate fragment in container.
Comments
Post a Comment