728x90

res > value > string 에 이용약관이나 라이센스 내용등을 넣어두고 textview 에 넣어서 사용중

'string to large' 라는 오류가 발생 했다.

잘 쓰고있는다가 왜지??! 했는데 구글링 해보니 여러 답변들이 있었지만 요약 하면.

 

문제

APK 파일에 32,767바이트(UTF-8로 인코딩) 이상의 문자열을 가질 수 없다.

 

솔루션

assets 폴더에 텍스트 파일을 만들어서 읽어오면 된다.

assets 폴더에 텍스트 파일을 읽은 메소드

fun getAssetsTestString(fileName: String): String{
    val termsString = StringBuilder()
    val reader: BufferedReader

    try {
        reader = BufferedReader(
        InputStreamReader(assets.open(fileName))
        )

        var str: String?
        while (reader.readLine().also { str = it } != null) {
        termsString.append(str)
        termsString.append('\n') //줄 변경
        }
        reader.close()
        return termsString.toString()

    } catch (e: IOException) {
    	e.printStackTrace()
    }
    return "fail"
}

 

출처: 

https://stackoverflow.com/questions/51732252/textview-shows-string-too-large

 

TextView shows STRING_TOO_LARGE

I have been trying to set a large string (25k+ characters) to a TextView for a while now but I've been getting a "STRING_TOO_LARGE" output. I read somewhere that setting the string in run time mi...

stackoverflow.com

https://stackoverflow.com/questions/33779607/reading-a-txt-file-and-outputing-as-a-textview-in-android

 

Reading a txt file and outputing as a TextView in Android

I am trying to read a text file that is already saved in my directory and print it on the screen as a TextView. This is the code that I have so far. However, when I run the application, it creates a

stackoverflow.com

 

728x90

+ Recent posts