Results 1 to 2 of 2
Thread: Insert Element in Array Problem
- 12-11-2011, 08:28 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
Insert Element in Array Problem
Hey guys,
the insertion of the element and the shifting of the others position worked quite well.
This is my code:
When i enter "7" as my position parameter i get "false" which is right and the object isnt inserted into the listJava Code:public boolean insert(int position, Object element) { for (int i = nextInsertPosition; i > position; i--) { array[i] = array[i-1]; } array[position] = element; nextInsertPosition++; if (position >= nextInsertPosition ) { return false;} return true; }
The Problem is that is get a NullPointerExeption as well.Java Code:System.out.println("Hinzufügen des Elementes war möglich: " + fahrzeuge.insert(7, schiff2));
I tried many different options but i cant figure out why.
Maybe some has an idea? :)
- 12-11-2011, 10:40 PM #2
Re: Insert Element in Array Problem
That statement is incorrect. You never do any checking other than returning true or false. The code before that (for loop etc) always inserts the object. Try printing out the array to test.
If you get any errors then you should post the full error message and indicate on which line it occurs. We don't read minds.The Problem is that is get a NullPointerExeption as well.
Similar Threads
-
JDOM how to insert Element:HELP!!!
By dottbin in forum XMLReplies: 1Last Post: 04-14-2011, 03:53 PM -
Variable of an object in an array compared to an element of another array?
By asmodean in forum New To JavaReplies: 23Last Post: 09-07-2010, 08:12 PM -
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM -
problem searching for a String element in a paralell array
By david185000 in forum New To JavaReplies: 4Last Post: 07-27-2010, 08:52 PM -
How to add an integer to a array element and the store that backinto an array.
By Hannguoi in forum New To JavaReplies: 1Last Post: 03-31-2009, 06:40 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks