0

i am really new to Android Studio and java programming.

im trying to create a new project, just to experimenting and learning.

this app there is long text and i using string to format it and also as resources.

however, after 1400+ text and formatting, the activity crash.

may i know is there some limit on string resources ?

and what is the way to overcome the problems ?

i figured out to use raw text, but on my current understanding, there is no way to format it like strings.

really appreciate if anyone can help.

\edit

here is the error

2021-02-20 14:03:15.512 26003-26003/? E/example.munaja: Unknown bits set in runtime_flags: 0x8000
2021-02-20 14:03:15.528 26003-26003/com.example.munajat E/libc: Access denied finding property "runtime.mmitest.isrunning"
2021-02-20 14:03:15.734 26003-26042/com.example.munajat E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@becf0c7

and here is full stack trace when i start the activity that crashed

2021-02-20 14:08:19.733 26422-26422/? I/example.munaja: Late-enabling -Xcheck:jni
2021-02-20 14:08:19.765 26422-26422/? E/example.munaja: Unknown bits set in runtime_flags: 0x8000
2021-02-20 14:08:19.767 26422-26422/? I/example.munaja: Reinit property: dalvik.vm.checkjni= false
2021-02-20 14:08:19.775 26422-26422/? W/re-initialized>: type=1400 audit(0.0:666616): avc: denied { read } for pid=26422 name="u:object_r:mmi_prop:s0" dev="tmpfs" ino=15380 scontext=u:r:untrusted_app:s0:c159,c257,c512,c768 tcontext=u:object_r:mmi_prop:s0 tclass=file permissive=0
2021-02-20 14:08:19.778 26422-26422/? E/libc: Access denied finding property "runtime.mmitest.isrunning"
2021-02-20 14:08:19.782 26422-26422/? D/ActivityThread: Attach thread to application
2021-02-20 14:08:19.925 26422-26422/com.example.munajat I/example.munaja: QarthPatchMonintor::Init
2021-02-20 14:08:19.925 26422-26422/com.example.munajat I/example.munaja: QarthPatchMonintor::StartWatch
2021-02-20 14:08:19.925 26422-26422/com.example.munajat I/example.munaja: QarthPatchMonintor::WatchPackage: /data/hotpatch/fwkhotpatch/
2021-02-20 14:08:19.925 26422-26422/com.example.munajat I/example.munaja: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/com.example.munajat
2021-02-20 14:08:19.925 26422-26422/com.example.munajat I/example.munaja: QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/all
2021-02-20 14:08:19.925 26422-26422/com.example.munajat I/example.munaja: QarthPatchMonintor::Run
2021-02-20 14:08:19.925 26422-26441/com.example.munajat I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.munajat#10415#256
2021-02-20 14:08:19.925 26422-26456/com.example.munajat I/example.munaja: QarthPatchMonintor::Reading
2021-02-20 14:08:19.925 26422-26441/com.example.munajat I/HwApiCacheMangerEx: apicache path=/storage/1538-291C state=mounted key=com.example.munajat#10415#256
2021-02-20 14:08:19.925 26422-26456/com.example.munajat I/example.munaja: QarthPatchMonintor::CheckNotifyEvent
2021-02-20 14:08:19.926 26422-26456/com.example.munajat I/example.munaja: QarthPatchMonintor::CheckNotifyEvent before read
2021-02-20 14:08:19.927 26422-26441/com.example.munajat I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.example.munajat#10415#0
2021-02-20 14:08:19.927 26422-26441/com.example.munajat I/HwApiCacheMangerEx: apicache path=/storage/1538-291C state=mounted key=com.example.munajat#10415#0
2021-02-20 14:08:19.930 26422-26441/com.example.munajat I/AwareBitmapCacher: init processName:com.example.munajat pid=26422 uid=10415
2021-02-20 14:08:19.962 26422-26458/com.example.munajat E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@b449e48
2021-02-20 14:08:19.999 26422-26422/com.example.munajat V/ActivityThread: callActivityOnCreate
2021-02-20 14:08:20.021 26422-26422/com.example.munajat V/HwWidgetFactory: : successes to get AllImpl object and return....
2021-02-20 14:08:20.047 26422-26422/com.example.munajat W/example.munaja: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-02-20 14:08:20.048 26422-26422/com.example.munajat W/example.munaja: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-02-20 14:08:20.060 26422-26422/com.example.munajat I/OverScrollerOptimization: start init SmartSlideOverScroller and get the overscroller config
2021-02-20 14:08:20.060 26422-26422/com.example.munajat I/OverScrollerOptimization: get the overscroller config
2021-02-20 14:08:20.246 26422-26422/com.example.munajat D/myLog: 2:08 pm
2021-02-20 14:08:20.253 26422-26422/com.example.munajat D/myLog: Sat Feb 20 14:08:20 GMT+08:00 2021
2021-02-20 14:08:20.253 26422-26422/com.example.munajat D/myLog: Saturday, 20 February 2021
2021-02-20 14:08:20.256 26422-26422/com.example.munajat D/ActivityThread: add activity client record, r= ActivityRecord{ebb44ec token=android.os.BinderProxy@91c585c {com.example.munajat/com.example.munajat.home}} token= android.os.BinderProxy@91c585c
2021-02-20 14:08:20.293 26422-26463/com.example.munajat D/HiTouch_PressGestureDetector: onAttached, package=com.example.munajat, windowType=1, mHiTouchRestricted=false
2021-02-20 14:08:20.329 26422-26460/com.example.munajat I/iGraphics: [0020080c] pn: com.example.munajat, p: 26422
2021-02-20 14:08:20.329 26422-26460/com.example.munajat I/iGraphics: [0030080c] no spt app: com.example.munajat
2021-02-20 14:08:20.346 26422-26460/com.example.munajat D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2021-02-20 14:08:20.419 26422-26460/com.example.munajat W/Gralloc3: mapper 3.x is not supported
2021-02-20 14:08:20.462 26422-26422/com.example.munajat I/HwViewRootImpl: removeInvalidNode jank list is null


Mr Learning
  • 73
  • 1
  • 9
  • 1
    What is the error listed in the error logs when the activity crashes? That should help point you toward if this is an issue with a text limit or not. – WOUNDEDStevenJones Feb 19 '21 at 18:11
  • I will check it soon, but for now, i sure it is something with limit as, there is no error showing on android studio, and i trying to add few lines of text with no format, it crash too. If it true because of text limit, may i know some ways to overcome it? – Mr Learning Feb 19 '21 at 18:17
  • And does string have limit? If so what is the limit? – Mr Learning Feb 19 '21 at 18:18
  • 1
    I'm not sure, but when an activity crashes in Android Studio in debug mode, you will be able to view the error in the logs (https://stackoverflow.com/questions/19784877/how-to-find-the-logs-on-android-studio) that will tell you the exact line that caused it to crash along with an error message (which can easily be searched for online for more details if needed). Without these logs added to your question, it's hard to guess what might be causing this issue. – WOUNDEDStevenJones Feb 19 '21 at 18:21
  • There's no inherent "string limit" or anything of that kind. Chances are that your application runs out of memory or some other resources. What exactly it is would become visible if we could see your logs, so please provide what WOUNDEDStevenJones asks for. – Joachim Sauer Feb 19 '21 at 18:25
  • Tq very much! I will provide it – Mr Learning Feb 19 '21 at 18:28
  • i provided it , really appreciate any answer :D – Mr Learning Feb 20 '21 at 06:39
  • Also providing a minimal sample code that can reproduce such error maybe helpful. – hata Feb 20 '21 at 11:39
  • I got string too large error on build. – Mr Learning Feb 20 '21 at 12:44

1 Answers1

1

String.length() method returns the length of the string. The length of the string is equal to the number of Unicode units in the string. The Java platform uses the UTF-16 representation in char arrays (each character takes two bytes), String, and StringBuffer classes.

The method returns the length which is of type int. So, the String maximum size is the same as the range of integer data type. The maximum length that would be returned by the method would be Integer.MAX_VALUE.

The size of int in Java is 4 bytes (included a signed bit, i.e. MSB). The range of integer data type is -231 to 231-1 (-2147483648 to 2147483647). Remember that we cannot use negative values for indexing. The indexing is done within the maximum range. It means that we cannot store the 2147483648th character. Therefore, the maximum length of String in Java is 0 to 2147483647. So, we can have a String with the length of 2,147,483,647 characters, theoretically.

import java.util.Arrays;

class StringMaxSize {
    public static void main(String args[]) {
        for (int i = 0; i < 1000; i++) {
            try {
                //Integer.MAX_VALUE is a constant that stores the maximum possible value for any integer variable  
                char[] array = new char[Integer.MAX_VALUE - i];
                //assign the specified data value to each element   
                Arrays.fill(array, 'a');
                //creating a constructor of the String class and parses an array into it  
                String str = new String(array);
                //determines and print the length of the string  
                System.out.println(str.length());
            } catch (Throwable e) {
                // returns the detail message string of this throwable  
                System.out.println(e.getMessage());
                //prints the maximum value  
                System.out.println("Last: " + (Integer.MAX_VALUE - i));
                System.out.println("Last: " + i);
            }
        }
    }
}

Output:

enter image description here

So, 1400+ text is not the actual issue.

For more details follow this link.

MC Emperor
  • 22,334
  • 15
  • 80
  • 130
Md Kawser Habib
  • 1,966
  • 2
  • 10
  • 25