6

I'm making an app where it looks up on a database (that I am currently building). I have done over 10/12 of it when I got the error:code too large as a Gradle Build message.

The java file is pretty much just a "database" (with data used in another class).

It has the following form:

static int[][] mDatabase10 = new int[][]{{1, 0, 0, 0, 11, 22},
        {1, 53, 42, 0, 41, 0},
        {7, 34, 11, 33, 32, 0}};

There are 80 arrays in each array of arrays (12 of these):

static int[][][][] dbDatabase = {{mDatabase10, mDatabase10a, mDatabase10b, mDatabase10c,
        mDatabase10d, mDatabase10e, mDatabase10f, mDatabase10g, mDatabase10h, mDatabase10i,
        mDatabase10j, mDatabase10k, mDatabase10l, mDatabase10m, mDatabase10n, mDatabase10o,
        mDatabase10p, mDatabase10q, mDatabase10r, mDatabase10s, mDatabase10t, mDatabase10u,
        mDatabase10v, mDatabase10w, mDatabase10x, mDatabase10y, mDatabase10z, mDatabase11a,
        mDatabase11b, mDatabase11c, mDatabase11d, mDatabase11e, mDatabase11f, mDatabase11g,
        mDatabase11h, mDatabase11i, mDatabase11j, mDatabase11k, mDatabase11l, mDatabase11m,
        mDatabase11n, mDatabase11o, mDatabase11p, mDatabase11q, mDatabase11r, mDatabase11s,
        mDatabase11t, mDatabase11u, mDatabase11v, mDatabase11w, mDatabase11x, mDatabase11y,
        mDatabase11z, mDatabase12a, mDatabase12b, mDatabase12c, mDatabase12d, mDatabase12e,
        mDatabase12f, mDatabase12g, mDatabase12h, mDatabase12i, mDatabase12j, mDatabase12k,
        mDatabase12l, mDatabase12m, mDatabase12n, mDatabase12o, mDatabase12p, mDatabase12q,
        mDatabase12r, mDatabase12s, mDatabase12t, mDatabase12u, mDatabase12v, mDatabase12w,
        mDatabase12x, mDatabase12y, mDatabase12z, mDatabase13a},

        {mDatabase20, mDatabase20a, mDatabase20b, mDatabase20c, mDatabase20d, mDatabase20e,
                mDatabase20f, mDatabase20g, mDatabase20h, mDatabase20i, mDatabase20j,
                mDatabase20k, mDatabase20l, mDatabase20m, mDatabase20n, mDatabase20o,
                mDatabase20p, mDatabase20q, mDatabase20r, mDatabase20s, mDatabase20t,
                mDatabase20u, mDatabase20v, mDatabase20w, mDatabase20x, mDatabase20y,
                mDatabase20z, mDatabase21a, mDatabase21b, mDatabase21c, mDatabase21d,
                mDatabase21e, mDatabase21f, mDatabase21g, mDatabase21h, mDatabase21i,
                mDatabase21j, mDatabase21k, mDatabase21l, mDatabase21m, mDatabase21n,
                mDatabase21o, mDatabase21p, mDatabase21q, mDatabase21r, mDatabase21s,
                mDatabase21t, mDatabase21u, mDatabase21v, mDatabase21w, mDatabase21x,
                mDatabase21y, mDatabase21z, mDatabase22a, mDatabase22b, mDatabase22c,
                mDatabase22d, mDatabase22e, mDatabase22f, mDatabase22g, mDatabase22h,
                mDatabase22i, mDatabase22j, mDatabase22k, mDatabase22l, mDatabase22m,
                mDatabase22n, mDatabase22o, mDatabase22p, mDatabase22q, mDatabase22r,
                mDatabase22s, mDatabase22t, mDatabase22u, mDatabase22v, mDatabase22w,
                mDatabase22x, mDatabase22y, mDatabase22z, mDatabase23a},

        //so on until mDatabase123a...

Finally there is function to return the requested array to the other class.

public static int[][] Chordlookup(int chordpart1, int chordpart2){

    return dbDatabase[chordpart1-1][chordpart2-1];
}

Now from my understanding reading on the internet about this problem, it is related to that the database.java class is too big. How can I solve this?

I'm open to suggestions as I am not so experienced with java...

EDIT:

A bit of description to what the code does:

each mDatabase is a chord (for example Cm7) each group of 6 ints is a position where to play that chord: {1, 0, 0, 0, 11, 22} Some chords might have one of these, some have more.

then in the dbDatabase each block (mDatabaseX0 to mDatabaseX3a) is a root (as in A,B,C,D,E,F,G)

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
Marshall
  • 1,353
  • 3
  • 17
  • 38
  • 3
    I have no idea what you are trying to do with that code, but it doesn't look like the right way to do it. Could you share with us what you are trying to achieve ? – 2Dee Jan 29 '15 at 10:46
  • Yes, sorry. I'll update the question – Marshall Jan 29 '15 at 10:47
  • 1
    See Peter Lawrey's answer. What you should probably do instead of writing the whole db in a class file, write it in a text file, to do INSERT statements in your DB (every Android app can have it's own DB). You could check this out : http://www.vogella.com/tutorials/AndroidSQLite/article.html. – 2Dee Jan 29 '15 at 10:55

1 Answers1

4

Code is limited to 64K bytes and when you initialize an array you do this in code.

The best option is to store the data in a file and read the data you need. Note: the file can be deployed with the application and obtain directly from the archive.

Another option is to use a String instead (multiple Strings are not so limited in length) and parse it.

EDIT:

I suggest you write the data in a human readable form like

Cm7 Bm6 Am7 ....
Dm8 Cm7 Dm8 ....
....
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • What kind of file should I use for this? Is there something I can read regarding this? – Marshall Jan 29 '15 at 10:53
  • 1
    @Marshall I would use a text file as it is easier to read and maintain. You may find using a `Scanner` is a simple way to read the data in. – Peter Lawrey Jan 29 '15 at 10:56