Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“如何解决错误”;java.lang.IllegalArgumentException:Can';t初始化配置的调试器&引用;突然_Java_Debugging_Exception_Smack - Fatal编程技术网

“如何解决错误”;java.lang.IllegalArgumentException:Can';t初始化配置的调试器&引用;突然

“如何解决错误”;java.lang.IllegalArgumentException:Can';t初始化配置的调试器&引用;突然,java,debugging,exception,smack,Java,Debugging,Exception,Smack,我想使用smack api和gtalk服务器来实现IM。 当我从本地系统运行它时,我的代码可以工作 import java.io.Console; import java.util.Collection; import java.util.List; import javax.net.ssl.SSLSocketFactory; import javax.servlet.RequestDispatcher; import javax.servlet

我想使用smack api和gtalk服务器来实现IM。 当我从本地系统运行它时,我的代码可以工作

    import java.io.Console;
    import java.util.Collection;
    import java.util.List;

    import javax.net.ssl.SSLSocketFactory;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.jivesoftware.smack.Chat;
    import org.jivesoftware.smackx.*;
    import org.jivesoftware.smack.ConnectionConfiguration;
    import org.jivesoftware.smack.MessageListener;
    import org.jivesoftware.smack.Roster;
    import org.jivesoftware.smack.RosterEntry;
    import org.jivesoftware.smack.XMPPConnection;
    import org.jivesoftware.smack.XMPPException;
    import org.jivesoftware.smack.packet.Message;
    import org.jivesoftware.smack.debugger.SmackDebugger;
    import org.jivesoftware.smack.filter.PacketFilter;
    import org.jivesoftware.smack.packet.Presence;


public class runcollectorAction extends Action implements MessageListener{

public static String username = "pqr";
public static String password ="mypwd";
XMPPConnection connection = new XMPPConnection("gmail.com");

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    XMPPConnection.DEBUG_ENABLED = true;
    System.out.println("okzzzz");
    String realtime=request.getParameter("collector");

    if(realtime!=null){
        boolean connectionStatus = connectToServer();
        displayUserList();
        if (connectionStatus){

            sendMessage(realtime,"abc@gmail.com");

        }

    System.out.println("Realtime  : "+ realtime);
    }
    return mapping.findForward("success");

}

public void sendMessage(String message, String to) throws   XMPPException
{
    System.out.println("Message is ... " + message);
    Chat chat = connection.getChatManager().createChat(to, this);
    chat.sendMessage(message);
}

@Override
public void processMessage(Chat chat, Message message) {
    // TODO Auto-generated method stub
    if ( message.getType() == Message.Type.chat){
        System.out.println(chat.getParticipant() + "says: " + message.getBody());

    }

}        

public boolean connectToServer() throws XMPPException{
    try {

        ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com",5222,"gmail.com");

        config.setCompressionEnabled(true);
        //config.setSASLAuthenticationEnabled(false);
        connection = new XMPPConnection(config);

        connection.connect();
        Thread.sleep(31000);
        System.out.println("connected to ... " + connection.getHost() );

        connection.login(username, password);

        System.out.println("authenticated .... " + connection.isAuthenticated());

    }
    catch (Exception e){
        e.printStackTrace();
        System.out.println("Error occured while connecting to server");
    }
    return true;
    //return connection.isConnected();

}

/**
 * Function to display user list
 */
public void displayUserList()
{
Roster roster = connection.getRoster();
roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
Collection<RosterEntry> entries = roster.getEntries();

System.out.println("\n\n" + entries.size() + " buddy(ies):");
for(RosterEntry r:entries)
    {
        System.out.println(r.getUser());
        Presence presence = roster.getPresence(r.getUser());
        System.out.println(r.getUser()+ " user is "+ presence.getMode());
    }
}
}
此外,它还给出了错误提示:“未连接到服务器”


如何解决这些错误???

这可能对您有所帮助

Nsmack api是我的类,这就是我使用其对象的原因。 在给定的代码中,只有以下语句是重要的-

XMPPConnection.DEBUG_ENABLED = false;
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(false);


private void connectionInit() throws XMPPException, IOException {
    // TODO Auto-generated method stub
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("... in main function .......");
    XMPPConnection.DEBUG_ENABLED = false;
    mySmackObj = new NSmackAPI();
    boolean status = mySmackObj.connectTOGTalk();
    boolean initial_status = true;
    mySmackObj.displayUserList();
    System.out.println("-----");

    String talkTo=RunMTNew.customer+"web@"+server;
    System.out.println(talkTo);
    System.out.println("-----");
    System.out.println("All messages will be sent to " + talkTo);
    System.out.println("Enter your message in the console:");
    System.out.println("-----\n");
    mySmackObj.sendMessage("Hi..are you there", talkTo);
  try{
      while(!(smsg=br.readLine()).equals(null)){
          mySmackObj.sendMessage(smsg, talkTo);
      }
  }
  catch(Exception e){
      System.out.println("sending failed");
      e.printStackTrace();
  }

}

boolean connectTOGTalk() throws XMPPException{

    try {


        ConnectionConfiguration config = new ConnectionConfiguration(server, 5222, server);
        config.setCompressionEnabled(true);
        config.setSASLAuthenticationEnabled(false);
        connection = new XMPPConnection(config);
        connection.connect();
        System.out.println("Username is "+username);
        System.out.println("Connected to " + connection.getHost());
        connection.login(username,password);
        System.out.println(connection.isAuthenticated());
        }
    catch (Exception e) {
        e.printStackTrace();
    }
    if(connection.isConnected()){
        return true;
    }
    else {
        return false;
    }
}

将此添加到我的配置中修复了我的问题

myConfig.setDebuggerEnabled(true);

我也遇到过这个问题。你们有什么办法弄明白吗?我得到了同样的问题,因为上面加了一行。如果我将
config.setDebuggerEnabled设置为
,那么它就可以正常工作了。但我想在我的连接上启用调试模式。无法在上述解决方案中工作。还有别的办法吗?
myConfig.setDebuggerEnabled(true);