Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java IRC Bot

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java IRC Bot

    Alright, so I am getting the messages perfectly from the Twitch Server, but when I go to section them off the bot crashes. This is the code I read the messages from, and this is very important to myself in order to make the bot function dynamically.

    public static void handleLine(String line) throws IOException {
         if (line == null) {throw new IllegalArgumentException("Can't process null line");}
              while ((line = in.readLine()) != null) {
    	       log("<<<" + line);
    	       if (line.startsWith("PING")) {
    	            sendRawLine(line.replace("PING", "PONG"));
    	       }
                   String[] args = line.split(":");
    	       String command = args[2]; // Line where it goes wrong.
                   if(command.contains("test")) {
    	            sendMessage("#peacebot","testing");
    	       }
    	  }
         }
    }

    I would appreciate it if anyone could help me with this, because I am rather new to Java but I am not new to IRC.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java IRC Bot

    the bot crashes
    What is the full text of the error message?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java IRC Bot

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
    	at me.mretech.peacebot.peacebot.handleLine(peacebot.java:46)
    	at me.mretech.peacebot.peacebot.connect(peacebot.java:30)
    	at me.mretech.peacebot.peacebot.main(peacebot.java:16)
    ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
    JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [../../../src/share/back/util.c:838]

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java IRC Bot

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
    at me.mretech.peacebot.peacebot.handleLine(peacebot.j ava:46)
    At line 46 the code uses an index (2) that is past the end of the array. The code should test the length of the array before trying to use an index past the end of the array.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Almost woring bot!
    By iceman in forum What's Wrong With My Code?
    Replies: 15
    Last Post: September 12th, 2012, 05:18 PM
  2. IRC client
    By Brt93yoda in forum The Cafe
    Replies: 14
    Last Post: November 26th, 2010, 04:31 PM
  3. Pinball bot
    By Johannes in forum Project Collaboration
    Replies: 16
    Last Post: August 13th, 2009, 07:59 AM