Reputation: 127
I am trying to make a chat application demo in android using quickblox,I have got a list of users successfully,and on click of usrlist i got its "id",I pass it to creating new chat dialog code,But it gives me Nullpointer at privatechatmanager.
my code is :
public Integer getOpponentIDForPrivateDialog(QBDialog dialog){
Integer opponentID = -1;
for(Integer userID : dialog.getOccupants()){
if(!userID.equals(getCurrentUser().getId())){
opponentID = userID;
break;
}
}
return opponentID;
}
logcat 06-16 17:11:07.817:
I/System.out(32408): =============MY SELECTED USER==============3588999
06-16 17:11:07.847: D/AndroidRuntime(32408): Shutting down VM
06-16 17:11:07.847: W/dalvikvm(32408): threadid=1: thread exiting with uncaught exception (group=0x418a3da0)
06-16 17:11:07.847: E/AndroidRuntime(32408): FATAL EXCEPTION: main
06-16 17:11:07.847: E/AndroidRuntime(32408): Process: com.amar.chums, PID: 32408
06-16 17:11:07.847: E/AndroidRuntime(32408): java.lang.NullPointerException
06-16 17:11:07.847: E/AndroidRuntime(32408): at com.amar.chums.activity.ManageConnection$2.onItemClick(ManageConnection.java:154)
06-16 17:11:07.847: E/AndroidRuntime(32408): at android.widget.AdapterView.performItemClick(AdapterView.java:313)
06-16 17:11:07.847: E/AndroidRuntime(32408): at android.widget.AbsListView.performItemClick(AbsListView.java:1507)
06-16 17:11:07.847: E/AndroidRuntime(32408): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3514)
06-16 17:11:07.847: E/AndroidRuntime(32408): at android.widget.AbsListView$3.run(AbsListView.java:5072)
06-16 17:11:07.847: E/AndroidRuntime(32408): at android.os.Handler.handleCallback(Handler.java:733)
06-16 17:11:07.847: E/AndroidRuntime(32408): at android.os.Handler.dispatchMessage(Handler.java:95)
06-16 17:11:07.847: E/AndroidRuntime(32408): at android.os.Looper.loop(Looper.java:146)
06-16 17:11:07.847: E/AndroidRuntime(32408): at android.app.ActivityThread.main(ActivityThread.java:5653)
06-16 17:11:07.847: E/AndroidRuntime(32408): at java.lang.reflect.Method.invokeNative(Native Method)
06-16 17:11:07.847: E/AndroidRuntime(32408): at java.lang.reflect.Method.invoke(Method.java:515)
06-16 17:11:07.847: E/AndroidRuntime(32408): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
06-16 17:11:07.847: E/AndroidRuntime(32408): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
06-16 17:11:07.847: E/AndroidRuntime(32408): at dalvik.system.NativeStart.main(Native Method)
Please help me to save my life..!!!
Upvotes: 0
Views: 365
Reputation: 125
Perform a validity check before both
dialog.getOccupants()
and
getCurrentUser().getId()
Make sure they have values in it.
Upvotes: 0
Reputation: 1768
try to handle the nullpointer
my_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
System.out
.println("=============MY SELECTED USER=============="
+ myConnections.get(position).get("id"));
QBDialog dialog = new QBDialog();
dialog.setType(QBDialogType.PRIVATE);
QBPrivateChatManager privateChatManager = QBChatService
.getInstance().getPrivateChatManager();
// try to handle the null value of both object
// i just discontinue the further code by returning the method ..do as per your requirement
// try to re-instialize or find the case..why its happen
if(privateChatManager == null || myConnections == null)
return;
privateChatManager.createDialog(
Integer.parseInt(myConnections.get(position).get("id")),
new QBEntityCallbackImpl<QBDialog>() {
@Override
public void onSuccess(QBDialog dialog, Bundle args) {
}
@Override
public void onError(List<String> errors) {
}
});
}
});
Upvotes: 1