Results 1 to 2 of 2
  1. #1
    helostcontrol is offline Member
    Join Date
    Dec 2011
    Rep Power

    Default 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:

    Java Code:
    public boolean insert(int position, Object element) {		
    		 for (int i = nextInsertPosition; i > position; i--) {
    		       array[i] = array[i-1]; 	   }
    		   array[position] = element;  
    		   if (position >= nextInsertPosition ) {
    		return false;}	
    		   return true;
    When i enter "7" as my position parameter i get "false" which is right and the object isnt inserted into the list
    Java Code:
     System.out.println("Hinzufügen des Elementes war möglich: " + fahrzeuge.insert(7, schiff2));
    The Problem is that is get a NullPointerExeption as well.
    I tried many different options but i cant figure out why.
    Maybe some has an idea? :)

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power

    Default Re: Insert Element in Array Problem

    Quote Originally Posted by helostcontrol View Post
    the object isnt inserted into the list
    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.
    The Problem is that is get a NullPointerExeption as well.
    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.

Similar Threads

  1. JDOM how to insert Element:HELP!!!
    By dottbin in forum XML
    Replies: 1
    Last Post: 04-14-2011, 04:53 PM
  2. Replies: 23
    Last Post: 09-07-2010, 09:12 PM
  3. Replies: 2
    Last Post: 09-06-2010, 02:03 AM
  4. Replies: 4
    Last Post: 07-27-2010, 09:52 PM
  5. Replies: 1
    Last Post: 03-31-2009, 07:40 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts