gpt4 book ai didi

java - 在 android 的 Quickblox 中创建新对话框时出现 nullpointerException

转载 作者:行者123 更新时间:2023-12-01 11:25:17 24 4
gpt4 key购买 nike

我正在尝试使用quickblox在android中制作一个聊天应用程序演示,我已经成功获得了用户列表,并且单击usrlist我得到了它的“id”,我将其传递给创建新的聊天对话框代码,但是它在 privatechatmanager 给我 Nullpointer。

我的代码是:

   public Integer getOpponentIDForPrivateDialog(QBDialog dialog){
Integer opponentID = -1;
for(Integer userID : dialog.getOccupants()){
if(!userID.equals(getCurrentUser().getId())){
opponentID = userID;
break;
}
}
return opponentID;
}

logcat06-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)

请帮助我拯救我的生命..!!!

最佳答案

尝试处理空指针

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) {

}
});
}
});

关于java - 在 android 的 Quickblox 中创建新对话框时出现 nullpointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30866426/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com