Click here to Skip to main content
15,914,165 members
Home / Discussions / Java
   

Java

 
GeneralRe: Need help with this code Pin
zooropean721-Oct-10 8:33
zooropean721-Oct-10 8:33 
GeneralRe: Need help with this code Pin
Richard MacCutchan21-Oct-10 11:21
mveRichard MacCutchan21-Oct-10 11:21 
GeneralRe: Need help with this code Pin
zooropean721-Oct-10 12:16
zooropean721-Oct-10 12:16 
GeneralRe: Need help with this code Pin
Bugclear21-Oct-10 20:31
Bugclear21-Oct-10 20:31 
GeneralRe: Need help with this code Pin
TorstenH.21-Oct-10 22:52
TorstenH.21-Oct-10 22:52 
GeneralRe: Need help with this code Pin
Bugclear21-Oct-10 23:22
Bugclear21-Oct-10 23:22 
GeneralRe: Need help with this code Pin
Richard MacCutchan22-Oct-10 3:05
mveRichard MacCutchan22-Oct-10 3:05 
QuestionException in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 Pin
vidhyaej20-Oct-10 0:19
vidhyaej20-Oct-10 0:19 
hi friends...

i am getting the following error while doing a program.....its a runtime error....can u please suggest a solution...also please tell me the reason for the same so that won't repeat the same next time also..

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at testThread.main(testThread.java:78)

My code is as following:

import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;

class testThread extends Frame implements ActionListener,Runnable
{
 int lower,upper;
 
 Label l1=new Label("ODD");
 Label l2=new Label("EVEN");
 List lb1=new List();
 List lb2=new List();
 Button b2=new Button("EXIT");

  void test(int low,int up)
 {
  lower = low;
  upper = up;
  setLayout(new FlowLayout());
  setSize(700,700);
  setTitle("Thread Demo");
  setVisible(true);
  add(l1);add(lb1);add(l2);add(lb2);add(b2);
  b2.addActionListener(this);
  Thread t=new Thread(this);
  t.start();

 addWindowListener(
              new WindowAdapter()
               {
                 public void windowClosing(WindowEvent e)
                   { System.exit(0); }
               }
             );

 }

 public void actionPerformed(ActionEvent ae)
 {
  if(ae.getSource()==b2)
    System.exit(0);
 }

 public void run()
 {
  try
  {
   if((lower % 2) != 0)
   {
   lower = lower + 1;
   }
   while(lower <= upper)
   {
    Thread.sleep(1000);
    lb2.add(String.valueOf(lower));
    lower += 2;
    Thread.sleep(500);
   }
  }catch(Exception e){}
 }


 public static void main(String[] args)
 {
     
             testThread obj=new testThread();

 
   
  		int lower,upper;
 		lower = Integer.parseInt(args[0]);
  		upper = Integer.parseInt(args[1]);

          obj.test(lower,upper);

  		if((lower % 2) == 0)
  			{
    				lower = lower + 1;
  			}

  		 try
    			{
      				while(lower <= upper)
      				{
        				Thread.sleep(1000);
        				obj.lb1.add(String.valueOf(lower));
        				lower = lower + 2;
        				Thread.sleep(500);
      				}
   			 }
   		 catch(Exception e){}
	 }
}

AnswerRe: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 Pin
TorstenH.20-Oct-10 0:56
TorstenH.20-Oct-10 0:56 
GeneralRe: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 Pin
vidhyaej20-Oct-10 1:03
vidhyaej20-Oct-10 1:03 
GeneralRe: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 Pin
TorstenH.20-Oct-10 1:19
TorstenH.20-Oct-10 1:19 
GeneralRe: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 Pin
vidhyaej20-Oct-10 1:29
vidhyaej20-Oct-10 1:29 
QuestionClasses and methods Pin
vidhyaej19-Oct-10 21:28
vidhyaej19-Oct-10 21:28 
AnswerRe: Classes and methods Pin
Nagy Vilmos19-Oct-10 22:01
professionalNagy Vilmos19-Oct-10 22:01 
GeneralRe: Classes and methods Pin
vidhyaej19-Oct-10 22:58
vidhyaej19-Oct-10 22:58 
GeneralRe: Classes and methods Pin
Richard MacCutchan19-Oct-10 23:23
mveRichard MacCutchan19-Oct-10 23:23 
GeneralRe: Classes and methods Pin
vidhyaej19-Oct-10 23:41
vidhyaej19-Oct-10 23:41 
GeneralRe: Classes and methods Pin
TorstenH.19-Oct-10 23:27
TorstenH.19-Oct-10 23:27 
GeneralRe: Classes and methods Pin
vidhyaej19-Oct-10 23:43
vidhyaej19-Oct-10 23:43 
QuestionPaint problem in java Pin
tamash_ionut19-Oct-10 13:01
tamash_ionut19-Oct-10 13:01 
AnswerRe: Paint problem in java Pin
Nagy Vilmos19-Oct-10 22:03
professionalNagy Vilmos19-Oct-10 22:03 
AnswerRe: Paint problem in java Pin
TorstenH.19-Oct-10 23:12
TorstenH.19-Oct-10 23:12 
QuestionRe: Paint problem in java Pin
tamash_ionut20-Oct-10 10:45
tamash_ionut20-Oct-10 10:45 
AnswerRe: Paint problem in java Pin
TorstenH.21-Oct-10 23:00
TorstenH.21-Oct-10 23:00 
QuestionGlassfish Deployment error Pin
JDragon31415919-Oct-10 11:09
JDragon31415919-Oct-10 11:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.