这是错误。我尝试了几件事,但仍然没有结果。
Process: com.lucastan96.flashchat, PID: 6114
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at com.lucastan96.flashchat.ChatListAdapter.getView(__ChatListAdapter.java:101__)
at android.widget.AbsListView.obtainView(AbsListView.java:2366)
at android.widget.ListView.makeAndAddView(ListView.java:2052)
at android.widget.ListView.fillUp(ListView.java:820)
at android.widget.ListView.layoutChildren(ListView.java:1793)
at android.widget.AbsListView.onLayout(AbsListView.java:2165)
at android.view.View.layout(View.java:20672)
at android.view.ViewGroup.layout(ViewGroup.java:6194)
boolean isMe = message.getAuthor().equals(mDisplayName);
setChatRowAppearance(isMe, holder);
String author = message.getAuthor();
holder.authorName.setText(author);
String msg = message.getMessage();
holder.body.setText(msg);
return convertView;
,第101行位于“ boolean isMe = message.getAuthor()。equals(mDisplayName);”
答案 0 :(得分:0)
boolean isMe = message.getAuthor().equals(mDisplayName);
在这里,message.getAuthor()
返回null
。
您可以通过调试来检查
解决方案:如果您希望应用程序不崩溃,则可以使用try catch块
例如:
try {
boolean isMe = message.getAuthor().equals(mDisplayName);
setChatRowAppearance(isMe, holder);
String author = message.getAuthor();
holder.authorName.setText(author);
String msg = message.getMessage();
holder.body.setText(msg);
}
catch (Exception e) {}
return convertView;