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)
4
  • What is the stack trace? Commented Jan 18, 2015 at 13:53
  • 1
    In theory? Any array can contain up to Integer.MAX_VALUE elements. But your memory may be limiting it. Commented Jan 18, 2015 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)" Commented Jan 18, 2015 at 13:58
  • Do you use external libraries? Maybe this post will help: stackoverflow.com/a/9522281/3579095 Commented Jan 18, 2015 at 14:06

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.