他の人がコメントできるトップポストメッセージをユーザーに許可する単純なアプリケーションがあります。mainActivityとcommentActivityという2つのアクティビティがあります。コメントの活動上のリストビュー私はどのようにrelativelayoutをリストビューのヘッダーとして使用するのですか?
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);
は私が
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");
を取得し、リストビューの上にある相対的なレイアウトに表示します。私が望むのは、相対レイアウトがlistviewと共に1としてスクロールすることです。私がしたことは、comment_activity.xmlとは別のヘッダ.xmlと呼ばれる相対的なレイアウトのための別のXMLを持っていることです。 commentActivityに私はjava.lang.NullPointerExceptionがを得るheader.xmlを膨らませると、リストビュー
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);
`
にヘッダとしてそれを使用しようとしました。 は、ここで私はそれが私が ListView listView = (ListView) findViewById(R.id.comment_list);
感謝を使用している必要があります ListView listView = (ListView) findViewById(R.id.comment_list_view)
によって引き起こされるエラーを考え出し
04-20 20:13:29.737 20254-20254/com.example.machimanapc.howzit W/System.err? at android.os.Looper.loop(Looper.java:193)
04-20 20:13:29.737 20254-20254/com.example.machimanapc.howzit W/System.err? at android.app.ActivityThread.main(ActivityThread.java:5299)
04-20 20:13:29.737 20254-20254/com.example.machimanapc.howzit W/System.err? at java.lang.reflect.Method.invokeNative(Native Method)
04-20 20:13:29.737 20254-20254/com.example.machimanapc.howzit W/System.err? at java.lang.reflect.Method.invoke(Method.java:515)
04-20 20:13:29.739 20254-20254/com.example.machimanapc.howzit W/System.err? at 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? at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
04-20 20:13:29.740 20254-20254/com.example.machimanapc.howzit W/System.err? at 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? at com.example.machimanapc.howzit.CommentActivity.onCreate(CommentActivity.java:196)
04-20 20:13:29.746 20254-20254/com.example.machimanapc.howzit W/System.err? at android.app.Activity.performCreate(Activity.java:5264)
04-20 20:13:29.746 20254-20254/com.example.machimanapc.howzit W/System.err? at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
04-20 20:13:29.746 20254-20254/com.example.machimanapc.howzit W/System.err? at 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 to start activity ComponentInfo{com.example.machimanapc.howzit/com.example.machimanapc.howzit.CommentActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
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)
Caused by: java.lang.NullPointerException
at com.example.machimanapc.howzit.CommentActivity.onCreate(CommentActivity.java:196)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at 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 at 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 from 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 at 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 from 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 at 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 from 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!
`
nullトレースを引き起こす原因を調べるためにスタックトレースを貼り付けることができます –
** getLayoutInflater **の代わりに – Maths
スタックトレースを追加しますLayoutinflater.from(context).inflate – Amir