0

I have the following code:

package com.sample.app;

import android.content.res.Resources;

import java.util.ArrayList;




public class Content {

    public static ArrayList<String> Names;
    public static ArrayList<String> NamesSub;
    public static ArrayList<String> Images;
    public static ArrayList<String> Wallpaper;
    public static ArrayList<String> Audio;
    public static ArrayList<String> BIG_Images;
    public static ArrayList<String> Sub_heading;
    public static ArrayList<String> Description;


    Content(){
        this.Names = new ArrayList<String>();
        this.NamesSub = new ArrayList<String>();
        this.Sub_heading = new ArrayList<String>();
        this.Images = new ArrayList<String>();
        this.Wallpaper = new ArrayList<String>();
        this.BIG_Images = new ArrayList<String>();
        this.Audio = new ArrayList<String>();
        this.Description = new ArrayList<String>();

        this.Description.add(0, "Long description");
        this.Description.add(1, "");
        this.Description.add(2, "");

    }

}

And have a too long description for ArrayList. when I paste the description it gave me

error: constant string too long

error. After that i tried setting values from strings.xml. I am using this code for getting values:

this.Description.add(0,String.valueOf(R.string.descvalue));

But when I run the app it prints numbers like this 2131689519 not my values.

After that i tried string-array

<string-array name="descvalue">
    <item>too long value</item>
</string-array>

And in the java file, I tried getting values with this code:

this.Description.add(0, getResources().getStringArray(R.array.descvalue)[0]);

But when I run the app it's crashing.

So what should I do in this case? Thanks.

1
  • The length of constant strings in java is limited to 64K during compile time. Commented Feb 16, 2020 at 15:45

2 Answers 2

1

"error: constant string too long"

for this, you can go with Text class

Text text = new Text("foo");
String s = text.getText(); 
text.setText(s); 

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

1 Comment

can you show me an example? i am sorry but i am newbie at java
1

Replace

this.Description.add(0,String.valueOf(R.string.descvalue));

With

this.Description.add(0,getString(R.string.descvalue));

but getString() needs a context.

2 Comments

getString turning red, i think i should add some codes right? how can i add context
you can obtain a context object from activity or fragment or application class depending on where you will put your code.

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.