android - How do i use relativelayout as header to listview -


i have simple app allows users top post messages others can comment on.i have 2 activities mainactivity , commentactivity.on mainactivity when user clicks on post on list view

intent intent = new intent(mainactivity.this, commentactivity.class); intent.putextra("appid", post.getobjectid()); intent.putextra("username", post.getuser().getusername()); intent.putextra("text", post.gettext()); intent.putextra("vote",integer.tostring(post.getvote())); intent.putextra("timestamp",long.tostring(post.gettimestamp())); startactivity(intent); 

on comment activity retrieve

string  username = intent.getstringextra("username"); string text     = intent.getstringextra("text"); post_id         = intent.getstringextra("appid"); string sum      = intent.getstringextra("vote"); string time     = intent.getstringextra("timestamp"); 

and displays them on relative layout above listview. want relative layout scroll listview 1 . did have separate xml relative layout called header .xml separate comment_activity.xml . on commentactivity tried inflate header.xml , use header listview

view view= getlayoutinflater().inflate(r.layout.header,null);     textview vote_count = (textview) view.findviewbyid(r.id.txtvote_count); textview txtusername =(textview) view.findviewbyid(r.id.txtusername_view_respond); textview statusmsg =(textview)  view.findviewbyid(r.id.txtcontent_view_respond);   txtusername.settext(username); statusmsg.settext(text); timestamp.settext(timeago);  listview listview = (listview)  findviewbyid(r.id.comment_list_view); listview.addheaderview(view); listview.setadapter(adapter);  

`

i java.lang.nullpointerexception. here stack trace `

  04-20 20:13:29.737  20254-20254/com.example.machimanapc.howzit w/system.err? @ android.os.looper.loop(looper.java:193) 04-20 20:13:29.737  20254-20254/com.example.machimanapc.howzit w/system.err? @ android.app.activitythread.main(activitythread.java:5299) 04-20 20:13:29.737  20254-20254/com.example.machimanapc.howzit w/system.err? @ java.lang.reflect.method.invokenative(native method) 04-20 20:13:29.737  20254-20254/com.example.machimanapc.howzit w/system.err? @ java.lang.reflect.method.invoke(method.java:515) 04-20 20:13:29.739  20254-20254/com.example.machimanapc.howzit w/system.err? @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:825) 04-20 20:13:29.740  20254-20254/com.example.machimanapc.howzit w/system.err? @ com.android.internal.os.zygoteinit.main(zygoteinit.java:641) 04-20 20:13:29.740  20254-20254/com.example.machimanapc.howzit w/system.err? @ dalvik.system.nativestart.main(native method) 04-20 20:13:29.740  20254-20254/com.example.machimanapc.howzit w/system.err? caused by: java.lang.nullpointerexception 04-20 20:13:29.746  20254-20254/com.example.machimanapc.howzit w/system.err? @ com.example.machimanapc.howzit.commentactivity.oncreate(commentactivity.java:196) 04-20 20:13:29.746  20254-20254/com.example.machimanapc.howzit w/system.err? @ android.app.activity.performcreate(activity.java:5264) 04-20 20:13:29.746  20254-20254/com.example.machimanapc.howzit w/system.err? @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1088) 04-20 20:13:29.746  20254-20254/com.example.machimanapc.howzit w/system.err? @ android.app.activitythread.performlaunchactivity(activitythread.java:2302) 04-20 20:13:29.746  20254-20254/com.example.machimanapc.howzit w/system.err? ... 11 more 04-20 20:13:29.746  20254-20254/com.example.machimanapc.howzit w/dalvikvm? threadid=1: calling uncaughtexceptionhandler 04-20 20:13:29.751  20254-20254/com.example.machimanapc.howzit e/androidruntime? fatal exception: main     process: com.example.machimanapc.howzit, pid: 20254     java.lang.runtimeexception: unable start activity componentinfo{com.example.machimanapc.howzit/com.example.machimanapc.howzit.commentactivity}: java.lang.nullpointerexception             @ android.app.activitythread.performlaunchactivity(activitythread.java:2338)             @ android.app.activitythread.handlelaunchactivity(activitythread.java:2390)             @ android.app.activitythread.access$800(activitythread.java:151)             @ android.app.activitythread$h.handlemessage(activitythread.java:1321)             @ android.os.handler.dispatchmessage(handler.java:110)             @ android.os.looper.loop(looper.java:193)             @ android.app.activitythread.main(activitythread.java:5299)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:515)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:825)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:641)             @ dalvik.system.nativestart.main(native method)      caused by: java.lang.nullpointerexception             @ com.example.machimanapc.howzit.commentactivity.oncreate(commentactivity.java:196)             @ android.app.activity.performcreate(activity.java:5264)             @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1088)             @ android.app.activitythread.performlaunchactivity(activitythread.java:2302)             at android.app.activitythread.handlelaunchactivity(activitythread.java:2390)             at android.app.activitythread.access$800(activitythread.java:151)             at android.app.activitythread$h.handlemessage(activitythread.java:1321)             at android.os.handler.dispatchmessage(handler.java:110)             at android.os.looper.loop(looper.java:193)             at android.app.activitythread.main(activitythread.java:5299)             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:825)             at com.android.internal.os.zygoteinit.main(zygoteinit.java:641)             at dalvik.system.nativestart.main(native method) 04-20 20:13:30.053  20254-23455/com.example.machimanapc.howzit d/dalvikvm? create interp thread : stack size=128kb 04-20 20:13:30.053  20254-23455/com.example.machimanapc.howzit d/dalvikvm? create new thread 04-20 20:13:30.053  20254-23455/com.example.machimanapc.howzit d/dalvikvm? new thread created 04-20 20:13:30.053  20254-23455/com.example.machimanapc.howzit d/dalvikvm? update thread list 04-20 20:13:30.055  20254-23457/com.example.machimanapc.howzit d/dalvikvm? threadid=14: interp stack @ 0x551f9000 04-20 20:13:30.055  20254-23457/com.example.machimanapc.howzit d/dalvikvm? init ref table 04-20 20:13:30.055  20254-23457/com.example.machimanapc.howzit d/dalvikvm? init mutex 04-20 20:13:30.055  20254-23457/com.example.machimanapc.howzit d/dalvikvm? threadid=14: created interp 04-20 20:13:30.055  20254-23455/com.example.machimanapc.howzit d/dalvikvm? start new thread 04-20 20:13:30.055  20254-23457/com.example.machimanapc.howzit d/dalvikvm? threadid=14: notify debugger 04-20 20:13:30.055  20254-23457/com.example.machimanapc.howzit d/dalvikvm? threadid=14 (task.background_executor-thread-13): calling run() 04-20 20:13:30.056  20254-23457/com.example.machimanapc.howzit d/dalvikvm? create interp thread : stack size=128kb 04-20 20:13:30.057  20254-23457/com.example.machimanapc.howzit d/dalvikvm? create new thread 04-20 20:13:30.057  20254-23457/com.example.machimanapc.howzit d/dalvikvm? new thread created 04-20 20:13:30.057  20254-23457/com.example.machimanapc.howzit d/dalvikvm? update thread list 04-20 20:13:30.059  20254-23458/com.example.machimanapc.howzit d/dalvikvm? threadid=15: interp stack @ 0x55219000 04-20 20:13:30.059  20254-23458/com.example.machimanapc.howzit d/dalvikvm? init ref table 04-20 20:13:30.059  20254-23458/com.example.machimanapc.howzit d/dalvikvm? init mutex 04-20 20:13:30.059  20254-23458/com.example.machimanapc.howzit d/dalvikvm? threadid=15: created interp 04-20 20:13:30.059  20254-23457/com.example.machimanapc.howzit d/dalvikvm? start new thread 04-20 20:13:30.059  20254-23458/com.example.machimanapc.howzit d/dalvikvm? threadid=15: notify debugger 04-20 20:13:30.059  20254-23458/com.example.machimanapc.howzit d/dalvikvm? threadid=15 (task.background_executor-thread-14): calling run() 04-20 20:13:30.060  20254-20272/com.example.machimanapc.howzit d/dalvikvm? create interp thread : stack size=128kb 04-20 20:13:30.060  20254-20272/com.example.machimanapc.howzit d/dalvikvm? create new thread 04-20 20:13:30.060  20254-20272/com.example.machimanapc.howzit d/dalvikvm? new thread created 04-20 20:13:30.060  20254-20272/com.example.machimanapc.howzit d/dalvikvm? update thread list 04-20 20:13:30.061  20254-23460/com.example.machimanapc.howzit d/dalvikvm? threadid=20: interp stack @ 0x55239000 04-20 20:13:30.061  20254-23460/com.example.machimanapc.howzit d/dalvikvm? init ref table 04-20 20:13:30.061  20254-23460/com.example.machimanapc.howzit d/dalvikvm? init mutex 04-20 20:13:30.061  20254-23460/com.example.machimanapc.howzit d/dalvikvm? threadid=20: created interp 04-20 20:13:30.061  20254-20272/com.example.machimanapc.howzit d/dalvikvm? start new thread 04-20 20:13:30.061  20254-23460/com.example.machimanapc.howzit d/dalvikvm? threadid=20: notify debugger 04-20 20:13:30.061  20254-23460/com.example.machimanapc.howzit d/dalvikvm? threadid=20 (task.background_executor-thread-15): calling run() 04-20 20:13:31.056  20254-23455/com.example.machimanapc.howzit d/dalvikvm? threadid=12: exiting 04-20 20:13:31.056  20254-23455/com.example.machimanapc.howzit d/dalvikvm? threadid=12: bye! 04-20 20:13:31.060  20254-23457/com.example.machimanapc.howzit d/dalvikvm? threadid=14: exiting 04-20 20:13:31.060  20254-23457/com.example.machimanapc.howzit d/dalvikvm? threadid=14: bye! 04-20 20:13:31.061  20254-23458/com.example.machimanapc.howzit d/dalvikvm? threadid=15: exiting 04-20 20:13:31.061  20254-23458/com.example.machimanapc.howzit d/dalvikvm? threadid=15: bye! 04-20 20:13:31.064  20254-23460/com.example.machimanapc.howzit d/dalvikvm? threadid=20: exiting 04-20 20:13:31.064  20254-23460/com.example.machimanapc.howzit d/dalvikvm? threadid=20: bye! 

`

i figured out error caused listview listview = (listview) findviewbyid(r.id.comment_list_view) should have used listview listview = (listview) findviewbyid(r.id.comment_list); thanks.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -