• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubts regarding ArrayLists

 
sagar shiraguppi
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class ArrayListDemo1 {
public static void main(String args[]) {
// create an ArrayList
ArrayList arl = new ArrayList();

System.out.println("Initial size of ArrayList: " + arl.size());

// adding dissimilar elements to the ArrayList
arl.add("C");
arl.add("A");
arl.add("E");
arl.add("B");
arl.add("D");
arl.add("F");
arl.add(1, "A2");
arl.add(null);

System.out.println("Size of ArrayList after additions: " + arl.size());

// display the ArrayList
System.out.println("Contents of ArrayList: " + arl);

// Remove elements from the ArrayList
arl.remove("F");
arl.remove(2);

System.out.println("Size of ArrayList after deletions: " + arl.size());
System.out.println("Contents of ArrayList after deletions: " + arl);

}

}



I am getting java runtime error in eclipse, I am not able to get the output of this program, please let me know the solution for this issue. Thanks in advance.
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the error that you are getting? It will help in figuring out the issue.
 
sagar shiraguppi
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I click on run in eclipse I am gettting "A java exception error occured message" after clicking on "ok" in that message, I am getting another message saying "Error:JNi error has occured, please check your installation or try again later".

But I can restart the eclipse and run other programs, but when I run this program, I get the above errors which I mentioned and I need to restart the eclipse to run other programs as well.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please use CODETAGS while posting your question.your Question would be easier to read then.

I think problem should be the retriving the null.
and also how can you print the contents of array without using any loop.
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That may be an Eclipse error and not a code error. Once I added the ArrayList import this code ran fine, other than giving me warnings abour adding a raw type to the ArrayList.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That error would indicate that your Eclipse installation -- or perhaps your Java installation itself -- are badly broken. It has nothing to do with this program that you're running. Your best course of action would be to find somebody local who can sit at your computer and help you sort that out.
 
sagar shiraguppi
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all.
sorry for the disturbance, I was really worried, now it is fine.
Issue is resolved, Just restarted the laptop.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is some problem in your eclipse java library..may be it is not there.

try checking your build path whether it exist or not
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic