• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem constructing a data array  RSS feed

 
Rui Miguel Fernandes
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good evening,

I'm trying to construct a Java Data array that includes data like this:



Now, as the constructor, I'm trying:



I only get an error: "type mismatch: cannot convert from int[][] to Myclass.main_struct"

I know I'm doing something wrong - of course....

Can someone help me out?

Kind regards,

Kepler
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This

Is saying to Java: "I'm declaring the variable data_01 to be an array of objects of the type main_struct"

After this you try to initialize it to a value which looks like an array of arrays, but it really isn't. You can't initialize objects this way.

Another issue I see in the code is that everything is declared as static. And you're not declaring a constructor with static class main_struct. Rather, you are declaring a static class. And by declaring the variables inside main_struct as static, you are making these variables global within the class main_struct.

You will have to create a proper constructor that will accept the values that you want your object's fields to have. And you will have to remove all those static modifiers from the variables you declare in main_struct. By the way, the naming convention in Java is to capitalize the first letter of a class name.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!