2

What is the maximum number of strings the String Array can hold in String Array in java? I am trying to fill a String array in java with as many as around 9000 entries and it is crashing

Thanks, Nerd

Process: com.example.Nerd.sample_app, PID: 3729
java.lang.VerifyError: Rejecting class com.example.Nerd.sample_app.MainActivity2 because it failed compile-time verification (declaration of 'com.example.Nerd.sample_app.MainActivity2' appears in /data/app/com.example.Nerd.sample_app-2/base.apk)
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at java.lang.Class.newInstance(Class.java:1572)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
        at android.app.ActivityThread.access$800(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
nerd
  • 339
  • 1
  • 5
  • 16
  • What is the stack trace? – DmitryKanunnikoff Jan 18 '15 at 13:53
  • 1
    In theory? Any array can contain up to `Integer.MAX_VALUE` elements. But your memory may be limiting it. – RealSkeptic Jan 18 '15 at 13:56
  • The error I get is this " java.lang.VerifyError: Rejecting class com.example.Nerd.sample_app.MainActivity2 because it failed compile-time verification (declaration of 'com.example.Nerd.sample_app.MainActivity2' appears in /data/app/com.example.Nerd.sample_app-1/base.apk)" – nerd Jan 18 '15 at 13:58
  • Do you use external libraries? Maybe this post will help: http://stackoverflow.com/a/9522281/3579095 – Lars Jan 18 '15 at 14:06

2 Answers2

1

The max size of any array (Object or primitive) is bound by the max size of an int -> 2^32 - 1. Approximately 2 billion.

Brett Okken
  • 6,210
  • 1
  • 19
  • 25
0

When you create a array you must specify the size of the array as a int. So in that case if you are having enough memory the maximum length of a array is Integer.MAX_VALUE which is equals to 2^31-1 But in real world scenarios this limit can be lot less than the actual maximum.