Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    iamsethi is offline Member
    Join Date
    Dec 2014
    Posts
    19
    Rep Power
    0

    Default Unable to concatenate two Arrays :(giggle)

    I am trying to concatenate two arrays but on on compiling it is showing Unable to concatenate two Arrays :(giggle)-mergesort.png
    Java Code:
    import static java.util.Arrays.*;
    class Mergesort
    {
    
    public static void main(String...s)
    		{
    		Mergesort r=new Mergesort();
    		int x[]={1,2,3,4,5,6};
    		int y[]={9,8,7,15,14,13,12,11};
    		int z[]=r.msort(x,y);
    		for(int i=0;i<z.length;i++)
    		System.out.println(z[i]);
    	
    		}
    
    	int[] msort(int x[],int y[])
    		{
    		int c[] = ArrayUtils.addAll(x,y);
    		Mergesort m=new Mergesort();
    		int w[]=m.sort(c);
    		return w;
    		
    		}
    
    
    
    
    
    		int[] sort(int x[])
    		{int temp;
    		for(int i=0;i<x.length;i++)
    			{
    			for(int j=1;j<(x.length)-i;j++)
    				{
    				if(x[j]<x[j-1])
    					{
    					temp=x[j];
    					x[j]=x[j-1];
    					x[j-1]=temp;
    					}
    				}
    			}
    		return x;
    		}
    		
    }
    Last edited by iamsethi; 12-15-2014 at 01:06 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Unable to concatenate two Arrays :(giggle)

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Please explain your problem.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Unable to concatenate two Arrays :(giggle)

    I can guess that it is something to do with "non-static method cannot be referenced from a static context".
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Unable to concatenate two Arrays :(giggle)

    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    iamsethi is offline Member
    Join Date
    Dec 2014
    Posts
    19
    Rep Power
    0

    Default Re: Unable to concatenate two Arrays :(giggle)

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at Sort2D.sort(Sort2D.java:19)
    at Sort2D.main(Sort2D.java:7)
    Last edited by iamsethi; 12-15-2014 at 02:24 PM.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Unable to concatenate two Arrays :(giggle)

    At line 19 the code used an index of -1. Look at the statement on line 19 and see how it got an index of -1. Change the code so it does not get an invalid index.
    The valid array indexes range in value from 0 to the array length-1.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

    Please don't use images. It is not possible to copy text from images to include in a response.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    iamsethi is offline Member
    Join Date
    Dec 2014
    Posts
    19
    Rep Power
    0

    Default Re: Unable to concatenate two Arrays :(giggle)

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at Sort2D.sort(Sort2D.java:19)
    at Sort2D.main(Sort2D.java:7)
    Attached Thumbnails Attached Thumbnails Unable to concatenate two Arrays :(giggle)-sort2d.png   Unable to concatenate two Arrays :(giggle)-mergesort.png  
    Last edited by iamsethi; 12-15-2014 at 02:24 PM.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Unable to concatenate two Arrays :(giggle)

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Unable to concatenate two Arrays :(giggle)

    What is an ArrayUtils?

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Unable to concatenate two Arrays :(giggle)

    Quote Originally Posted by Norm View Post
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    Or right click -> mark
    select all text
    right click again

    At this point the selected text is copied to the clipboard. Far less clickety-click :)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    iamsethi is offline Member
    Join Date
    Dec 2014
    Posts
    19
    Rep Power
    0

    Default Re: Unable to concatenate two Arrays :(giggle)

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at Sort2D.sort(Sort2D.java:19)
    at Sort2D.main(Sort2D.java:7)

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Unable to concatenate two Arrays :(giggle)

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at Sort2D.sort(Sort2D.java:19)
    The index is -1 when the statement on line 19 is executed. The valid indexes range from 0 to the array's length -1. Check the code on line 19 to see how it got a value of -1. Then change the code so the index is valid.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Unable to concatenate two Arrays :(giggle)

    Quote Originally Posted by iamsethi View Post
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at Sort2D.sort(Sort2D.java:19)
    at Sort2D.main(Sort2D.java:7)
    See my reply in your other thread: http://www.java-forums.org/new-java/...exception.html

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  14. #14
    iamsethi is offline Member
    Join Date
    Dec 2014
    Posts
    19
    Rep Power
    0

    Default Re: Unable to concatenate two Arrays :(giggle)

    Mergesort.java:20: error: cannot find symbol
    int c[] = ArrayUtils.addAll(x,y);
    ^
    symbol: variable ArrayUtils
    location: class Mergesort
    1 error

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Unable to concatenate two Arrays :(giggle)

    symbol: variable ArrayUtils
    Where is ArrayUtils defined? The compiler can not find it.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    iamsethi is offline Member
    Join Date
    Dec 2014
    Posts
    19
    Rep Power
    0

    Default Re: Unable to concatenate two Arrays :(giggle)

    I dont know it.I've copied the code from website.i am new to JAVA ,i dont know how to define ArrayUtils :(

  17. #17
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Unable to concatenate two Arrays :(giggle)

    If you really don't want to do the right thing and learn how to write the code yourself, then you should simply copy other code from another site until you find one that does compile. There are dozens of examples on the net and most of them do not rely on an Apache commons-lang class.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Unable to concatenate two Arrays :(giggle)

    I've copied the code from website.
    Go back to the website and find a definition for the missing class.
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    iamsethi is offline Member
    Join Date
    Dec 2014
    Posts
    19
    Rep Power
    0

    Default Re: Unable to concatenate two Arrays :(giggle)

    Can you please tell me how to use Apache commons-lang class.It'll be really appreciable :)

  20. #20
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Unable to concatenate two Arrays :(giggle)

    What do you hope to gain from compiling and running the posted code? You would be better served by writing some of your own programs and running them. They don't have to be complicated.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Page 1 of 2 12 LastLast

Similar Threads

  1. APP: Concatenate images - H E L P
    By irreconhecivell in forum Advanced Java
    Replies: 8
    Last Post: 10-30-2014, 11:26 PM
  2. how to concatenate two arraylists in a third one
    By nanees in forum New To Java
    Replies: 14
    Last Post: 03-31-2011, 05:08 PM
  3. How to concatenate a number
    By jim01 in forum New To Java
    Replies: 4
    Last Post: 03-27-2011, 03:31 AM
  4. Concatenate year from DATETIME
    By ashin in forum SWT / JFace
    Replies: 11
    Last Post: 07-30-2010, 05:34 PM
  5. Concatenate Linked Lists
    By tttestall in forum New To Java
    Replies: 1
    Last Post: 04-20-2010, 07:03 PM

Posting Permissions

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