有些时间并没有错误,它的运行没有错误但是大部分时间都在这段代码中出错了,我为此尝试了很多东西。我尝试在onStart()
上调用此代码,并在onActivityCreted()
上尝试此操作。但我得到同样的错误。这是我之前聊天的编码。我在limit()
中收到了错误。
final ListView listView = getListView();
mChatListAdapter = new FirebaseListAdapter<>(mFirebaseRef.limit(50), Chat.class, R.layout.chat_item, R.layout.chat_item_other,
R.layout.third_layout_chat, R.layout.fourth_layout_chat, getActivity(), chat_id);
listView.setAdapter(mChatListAdapter);
mChatListAdapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
super.onChanged();
listView.setSelection(mChatListAdapter.getCount() - 1);
}
});
这是错误。
FATAL EXCEPTION: main Process: com.socialapp.android, PID: 8112 Theme: themes:{} java.lang.RuntimeException: Unable to start activity ComponentInfo{com.socialapp.android/com.socialapp.chat.ChatViewActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.firebase.client.Query com.firebase.client.Firebase.limit(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5466)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.firebase.client.Query com.firebase.client.Firebase.limit(int)' on a null object reference
at com.socialapp.chat.ChatViewFragment.onStart(ChatViewFragment.java:609)
at android.app.Fragment.performStart(Fragment.java:2244)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1002)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1130)
at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:1958)
at android.app.FragmentController.dispatchStart(FragmentController.java:163)
at android.app.Activity.performStart(Activity.java:6274)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5466)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)