The Artima Developer Community
Sponsored Link

Java Answers Forum
LinkedList

26 replies on 2 pages. Most recent reply: Oct 8, 2003 12:41 AM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 26 replies on 2 pages [ « | 1 2 ]
Subha

Posts: 16
Nickname: nikki
Registered: Sep, 2003

Re: LinkedList Posted: Oct 2, 2003 1:17 PM
Reply to this message Reply
Advertisement
I dry ran the program.I see that I have initialized the array only once.I am able to figure out any other problem.
Please help.
Thanks

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: LinkedList Posted: Oct 2, 2003 2:49 PM
Reply to this message Reply
here is a portion of your log.

i am here
iam initialized
I am here2
UAV : 2 NE - Row :10 Col: 2

i am here
iam initialized
I am here2
UAV : 3 NE - Row :10 Col: 2

i am here
iam initialized
I am here2
UAV : 4 E - Row :1 Col: 2

i am here
iam initialized
I am here2
UAV : 5 E - Row :1 Col: 2


Check in your code where you are printing the iam initialized messages. Its after those foor loops initialising the array right??? then how come it prints iam initialized multiple times if it is only initialised once?

Subha

Posts: 16
Nickname: nikki
Registered: Sep, 2003

Re: LinkedList Posted: Oct 2, 2003 3:02 PM
Reply to this message Reply
No,this is what I am getting.Its initializing only once.

UAVs Starts to move
i am here
iam initialized
I am here2
UAV : 1 NW - Row :10 Col: 10
I am here2
UAV : 2 NW - Row :10 Col: 10
I am here2
UAV : 3 NW - Row :10 Col: 10
I am here2
UAV : 4 NW - Row :10 Col: 10
I am here2
UAV : 5 NW - Row :10 Col: 10
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
        at java.util.LinkedList.entry(LinkedList.java:360)
        at java.util.LinkedList.get(LinkedList.java:303)
        at ThreadHandler.UAVCoordinates(uavmaze1.java:135)
        at ThreadHandler.run(uavmaze1.java:340)
java.lang.NullPointerException
        at ThreadHandler.UAVCoordinates(uavmaze1.java:133)
        at ThreadHandler.run(uavmaze1.java:340)
java.lang.NullPointerException
        at ThreadHandler.UAVCoordinates(uavmaze1.java:133)
        at ThreadHandler.run(uavmaze1.java:340)
java.lang.NullPointerException
        at ThreadHandler.UAVCoordinates(uavmaze1.java:133)
        at ThreadHandler.run(uavmaze1.java:340)
java.lang.NullPointerException
        at ThreadHandler.UAVCoordinates(uavmaze1.java:133)
        at ThreadHandler.run(uavmaze1.java:340)

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: LinkedList Posted: Oct 2, 2003 5:03 PM
Reply to this message Reply
Have you considered looking at line 340 of uavmaze1.java? I haven't, but I'd guess that you've only added one item to your LinkedList and then you are trying to index it at position 1, which would be the second item in the list.

Like I said, I didn't look too closely at your code, but this exception is pretty easy to simulate:
class Croak
{
   public static void main(String args[])
   {
      java.util.LinkedList froggies = new java.util.LinkedList();
      froggies.add( "Kermit" );
      froggies.get( froggies.size() );  // Oops!
      System.out.println("Ribbit!");
   }
}
Results in this:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.LinkedList.entry(Unknown Source)
at java.util.LinkedList.get(Unknown Source)
at Croak.main(Croak.java:7)

Subha

Posts: 16
Nickname: nikki
Registered: Sep, 2003

Re: LinkedList Posted: Oct 3, 2003 10:20 AM
Reply to this message Reply
I could get the program to work,but it seems to run for just 1 thread.Its not outputting results for all threads.
Do you know why?

Subha

Posts: 16
Nickname: nikki
Registered: Sep, 2003

Re: LinkedList Posted: Oct 5, 2003 1:06 PM
Reply to this message Reply
Hi,
I am able to run my program to get the results i want.but i have a problem with the delay statement i think.I am not able to set it right.It would be really grateful if you can help me out with that.I am sending my program again.
Thanks a ton!
import java.io.*;
import java.net.*;
import java.util.*;
import java.lang.*;
 
 
class uavmaze1
{  
  public static void main(String args[]) 
   { 
    
      System.out.println("UAVs Starts to move");
 
      int i=1, delayCount;
 
      int initCount = 0;
       
      while (i!=6)
        {  
            if(i==1)    {           
                System.out.println("I # " + i);
                ThreadHandler thread = new ThreadHandler(i,initCount); 
                  thread.start();             
            
                 }
            else 
               {
                 initCount++;
                 System.out.println("I # " + i);	 
                 ThreadHandler thread = new ThreadHandler(i,initCount);              
                 thread.start();
 
               }
                  
               for(delayCount=0;delayCount<=190;delayCount++)
                {
                  delayCount = delayCount++;
                }
		 
          
            //increment i to label the next connection
            i++;
         } 
 
   }
 
 
}
 
 
 
//define the thread class for handling new connection
class ThreadHandler extends Thread
{ 
   public int number;            //label for the connection   
 
   public LinkedList[][] uavArray;
 
   public int row, col;
 
   private int index,jndex;
 
   OutputStreamWriter out;   
 
   private int initCount;
 
   public int globalTime;
 
   public int a;
 
   public int siz;
 
 
   public ThreadHandler(int id, int indexCount) 
 
   {
      number = id;
 
      initCount = indexCount;
 
      row = 1;
 
      col = 1; 
     
   }
  
 
     public void newInit() 
     {
      
   
      //Declare and initialize the array
 
      uavArray = new LinkedList[11][11];
 
      for(index=1;index<=10;index++)
         for(jndex=1;jndex<=10;jndex++)
             
            {
              uavArray[index][jndex] = new LinkedList(); 
              uavArray[index][jndex].addFirst(new Integer(0));               
             } 
 
      index =0;
 
      //All points start from coordinate (1,1)
 
      globalTime = 1;
            
      
      //open a file and its handle for updation
  
      try {
       FileOutputStream fout = new FileOutputStream("uavFile.txt");
       OutputStreamWriter out = new OutputStreamWriter(fout, "8859_1");              
       }
 
       catch (IOException e) {
          System.err.println(e); 
         }               
    }
 
  
 
   public void UAVCoordinates(int number, int posRandom)
    {
 
      //Generate Random number between 1 And 8
 
      System.out.println("Inside UAV # " + number);
 
      globalTime++;
            
      switch (posRandom) {
 
            case 1: 
 
                    //Decrease both row and col -- NW
                    
                    if(row==1)
                       row=10;
                    else 
                       row = row - 1;
               
                    if(col==1)
                       col=10;
                    else
                       col = col - 1;  
                    
                    //System.out.println("UAV : " + number + " NW - Row :" + row + " Col: " + col + "\n");
                    
                    
                    siz = (uavArray[row][col].size());
                  
                    a  = ((Integer)(uavArray[row][col].get(siz-1))).intValue();
                    
                    uavArray[row][col].addLast(new Integer(globalTime - a));
 
                    break;
 
            case 2: 
   
 
                    //Decrease row -- North
                    if(row==1)
                       row=10;
                    else 
                      {
                      row = row - 1;
                      col = col;
                      }
                      
                    //System.out.println("UAV : " + number + " N - Row :" + row + " Col: " + col + "\n");
 
                    siz = (uavArray[row][col].size());
                 
                    a  = ((Integer)(uavArray[row][col].get(siz-1))).intValue();
                    
                    uavArray[row][col].addLast(new Integer(globalTime - a));
                                         
                    break;
 
            case 3: 
                    
                    //Decrease row and Increase col - NE
                  
                    if(row==1)
                       row=10;
                    else
                       row = row - 1;
                    
                    if(col==10)
                       col = 1;
                    else
                       col = col + 1;   
 
                    //System.out.println("UAV : " + number + " NE - Row :" + row + " Col: " + col + "\n");
 
                    siz = (uavArray[row][col].size());
                   
                    a  = ((Integer)(uavArray[row][col].get(siz-1))).intValue();
                    
                    uavArray[row][col].addLast(new Integer(globalTime - a));
 
                    break;
 
            case 4: 
 
                    //Increase col - East
 
                    if(col==10)
                       col = 1;
                    else
                       col = col + 1;                                       
 
                    //System.out.println("UAV : " + number + " E - Row :" + row + " Col: " + col + "\n");
 
                    siz = (uavArray[row][col].size());
                 
                    a  = ((Integer)(uavArray[row][col].get(siz-1))).intValue();
                    
                    uavArray[row][col].addLast(new Integer(globalTime - a));
 
                    break;
 
            case 5: 
                    
                    //Increase Row And Col -- SE
 
                    if(col==10)
                       col = 1;
                    else
                       col = col + 1;   
 
                    if(row==10)
                       row = 1;
                    else
                       row = row + 1;   
 
 
                    //System.out.println("UAV : " + number + " SE - Row :" + row + " Col: " + col + "\n");
 
                    siz = (uavArray[row][col].size());
                 
                    a  = ((Integer)(uavArray[row][col].get(siz-1))).intValue();
                    
                    uavArray[row][col].addLast(new Integer(globalTime - a));
                    
                    break;
 
            case 6: 
 
                    // Increase row -- South
                 
                    if(row==10)
                       row = 1;
                    else
                       row = row + 1;   
                     
                    //System.out.println("UAV : " + number +  " S - Row :" + row + " Col: " + col + "\n");
 
                    siz = (uavArray[row][col].size());
                  
                    a  = ((Integer)(uavArray[row][col].get(siz-1))).intValue();
                    
                    uavArray[row][col].addLast(new Integer(globalTime - a));
 
                    break;
 
            case 7: 
 
                    //Increase row and Decrease Col -- SW
                    
                    if(row==10)
                      row=1;
                    else
                      row = row + 1;
     
                    if(col==1)
                       col=10;
                    else
                       col = col - 1;   
 
                    //System.out.println("UAV : " + number +  " SW - Row :" + row + " Col: " + col + "\n");  
 
                    siz = (uavArray[row][col].size());
                 
                    a  = ((Integer)(uavArray[row][col].get(siz-1))).intValue();
                    
                    uavArray[row][col].addLast(new Integer(globalTime - a));
                         
                    break;
 
            case 8: 
 
                    //Decrease col -- W
                    
                    if(col==1) 
                       col=10;
                    else
                       col = col + 1;                       
			                    
                    //System.out.println("UAV : " + number + " W - Row :" + row + " Col: " + col + "\n");
 
                    siz = (uavArray[row][col].size());
                  
                    a  = ((Integer)(uavArray[row][col].get(siz-1))).intValue();
                    
                    uavArray[row][col].addLast(new Integer(globalTime - a));
                 
                    break; 
 
             default:
 
              }
 
        }       
           
 
 
   public void run()
   {  
     
     int inCount=0,i,j,k;
 
     while(inCount!=1000)
     {
        if(initCount==0)
          {  
           initCount=1; 
           newInit();
          } 
 
        //System.out.println("Inside RUN # " + number);        
 
        Random generator = new Random();
 
        int posRandom = generator.nextInt(7) + 1;    
 
        UAVCoordinates(number,posRandom); 
               
        inCount++;
     }
          
 
    System.out.println("\n\n"); 
 
   
   System.out.println("*******************************************************"); 
     for(i=1;i<=10;i++)
       for(j=1;j<=10;j++)
    System.out.println("No of visits to location ( " + i + "," + j + ") >> " + uavArray[i][j] + "\n");
            
 
   } //run closes
 
  } //class threadhandler closed

Kunchithapatham

Posts: 5
Nickname: sivam
Registered: Oct, 2003

1. Serial port connection through web based solution Posted: Oct 7, 2003 3:01 AM
Reply to this message Reply
Hi Guys,



I am my doing my computer project for my final year. As usual like everyone else at this stage I am also at the research stage to find out the suitable project topic within my interest areas. As usual the normal project guideline is that this has to be unique in some sense.



I am interested in project related to the areas I have listed below.



1. Java.

2. Oracle

3. Graphics

4. little bit of XML





I have couple of ideas which I already collected, I am listing them down below.



1. Serial port connection through web based solution.



This is basically to provide a client server (most probably RMI client and server) model to access a serial port through a remote machine. I am also planning to give a Web Interface where a user can manage multiple such connections. I think this would be useful mostly in telecom industry since all the telecom switches support serial port communication it will be able to provision services remotely.


I am looking for any new ideas you guys have or any criticism for the ideas I have presented which will enable me to refine my ideas? Please help me out here,



Thank you for your time.

Subha

Posts: 16
Nickname: nikki
Registered: Sep, 2003

Re: 1. Serial port connection through web based solution Posted: Oct 7, 2003 9:55 AM
Reply to this message Reply
Hello All,
I got my program to work.Thanks for all your help!
Subha.

Kunchithapatham

Posts: 5
Nickname: sivam
Registered: Oct, 2003

Re: 1. Serial port connection through web based solution Posted: Oct 7, 2003 8:00 PM
Reply to this message Reply
Well is it about the Serial port connection ?????
Well thatÂ’s good can u help with that .Is their any suggestion to made in my topics

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: LinkedList Posted: Oct 7, 2003 9:14 PM
Reply to this message Reply
Senthoorkumaran,

Try posting a new topic instead of tacking onto an unrelated subject.

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: LinkedList Posted: Oct 7, 2003 10:49 PM
Reply to this message Reply
> Senthoorkumaran,
>
> Try posting a new topic instead of tacking onto an
> unrelated subject.

Hay Matt,

How come my name is mentioned in your post? Which post you are reffering to? I am really confuced here...

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: LinkedList Posted: Oct 8, 2003 12:41 AM
Reply to this message Reply
Oops, sorry Senthoorkumaran, that should have been Kunchithapatham. I wasn't paying attention to my paste buffer. ...Hmm... I hope I didn't accidentally vote for Arnold Schwarzenegger, too...

Flat View: This topic has 26 replies on 2 pages [ « | 1  2 ]
Topic: Problem with CallableStatement and PreparedStatement - Urgent Previous Topic   Next Topic Topic: ?? Tool that produce Exe from Japa application ??

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use