0

It doesn't recognize item[1] I guess it's because the method is declared as a string in public static void main(STRING[] args). But how else should I declare the main method in oder to have the Integers accepted?

This is the message Eclips comes up with: Exception in thread "main" java.lang.ArrayStoreException: [Ljava.lang.Integer; at Package1.test7.main(test7.java:18)


// import java.util.arrays;

public class test7

{    



    public static void main(String[] args)
    {

    Object[][] items = new String[2][]; 
    items[0] = new String[]{"a", "b"}; 
(18)items[1] = new Integer[]{1, 2, 4}; 


    System.out.println (items[0]);

    }   

}


halfelf
  • 9,737
  • 13
  • 54
  • 63
  • `Object[][] items = new Object[2][];` – Kevin Anderson Oct 19 '19 at 14:45
  • Initialize the array like so `Object[][] items = new Object[2][];` and remove that `(18)`. – Alex R Oct 19 '19 at 14:45
  • @Alex R. Thanks. Pretty weid, I copied it from https://javarevisited.blogspot.com/2016/02/6-example-to-declare-two-dimensional-array-in-java.html. I know about that 18, that was only to show that that was line #18. –  Oct 19 '19 at 14:51
  • Hard to believe that something you read on the internet wasn't true (;->). What's the world coming to? – Kevin Anderson Oct 19 '19 at 14:54
  • This guy probably just made a mistake. Take a look in the comment section of the article, there are people pointing that out. – Alex R Oct 19 '19 at 14:55
  • @Kevin Anderson, thanks you too, Not bad for a Tennis player!! ;-) –  Oct 19 '19 at 14:59

0 Answers0