Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android studio上的字符串限制_Java_Android_String - Fatal编程技术网

Java android studio上的字符串限制

Java android studio上的字符串限制,java,android,string,Java,Android,String,我对Android Studio和java编程真的很陌生 我正在尝试创建一个新项目,只是为了实验和学习 这个应用程序有很长的文本,我使用字符串格式化它,也作为资源 但是,在1400多个文本和格式设置之后,活动崩溃 请问字符串资源是否有限制 克服这些问题的方法是什么 我想使用原始文本,但根据我目前的理解,没有办法将其格式化为字符串 如果有人能帮忙,我真的很感激 \编辑 这里是错误 2021-02-20 14:03:15.512 26003-26003/? E/example.munaja: Unk

我对Android Studio和java编程真的很陌生

我正在尝试创建一个新项目,只是为了实验和学习

这个应用程序有很长的文本,我使用字符串格式化它,也作为资源

但是,在1400多个文本和格式设置之后,活动崩溃

请问字符串资源是否有限制

克服这些问题的方法是什么

我想使用原始文本,但根据我目前的理解,没有办法将其格式化为字符串

如果有人能帮忙,我真的很感激

\编辑

这里是错误

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
这是启动崩溃的活动时的完整堆栈跟踪

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


String.length()
方法返回字符串的长度。字符串的长度等于字符串中的Unicode单位数。Java平台在char数组(每个字符占用两个字节)、String和StringBuffer类中使用UTF-16表示

该方法返回int类型的长度。因此,字符串
最大大小
与整数数据类型的
范围相同。该方法返回的最大长度为
Integer.MAX\u VALUE

Java中int的大小为4字节(包括有符号位,即MSB)。整数数据类型的范围为-231到231-1(-2147483648到2147483647)。请记住,索引时不能使用负值。索引是在最大范围内完成的。这意味着我们无法存储2147483648个字符。因此,Java中字符串的最大长度为0到2147483647。理论上,我们可以得到一个长度为2147483647个字符的字符串

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);
            }
        }
    }
}
导入java.util.array;
类StringMaxSize{
公共静态void main(字符串参数[]){
对于(int i=0;i<1000;i++){
试一试{
//Integer.MAX_VALUE是一个常数,用于存储任何整数变量的最大可能值
char[]数组=新字符[Integer.MAX_VALUE-i];
//为每个元素指定指定的数据值
数组。填充(数组'a');
//创建String类的构造函数并将数组解析到其中
String str=新字符串(数组);
//确定并打印字符串的长度
System.out.println(str.length());
}捕获(可丢弃的e){
//返回此可丢弃文件的详细信息字符串
System.out.println(e.getMessage());
//打印最大值
System.out.println(“Last:”+(Integer.MAX_VALUE-i));
System.out.println(“Last:+i”);
}
}
}
}
输出:

因此,1400+文本不是实际问题


有关更多详细信息,请参见。

当活动崩溃时,错误日志中列出的错误是什么?这将帮助您了解这是否是一个文本限制问题。我将很快检查它,但现在,我确定它是有限制的,因为在android studio上显示没有错误,并且我尝试添加几行没有格式的文本,它也崩溃了。如果是因为文本限制,我可以知道一些克服它的方法吗?字符串有限制吗?如果是,限制是什么?我不确定,但是当一个活动在Android Studio中以调试模式崩溃时,您将能够在日志()中查看错误,日志()将告诉您导致它崩溃的确切行以及错误消息(如果需要,可以很容易地在线搜索更多详细信息)。如果没有这些日志添加到您的问题中,很难猜测是什么导致了这个问题。没有固有的“字符串限制”或类似的东西。应用程序很可能会耗尽内存或其他资源。如果我们能看到您的日志,那么它的具体内容将变得可见,因此请提供WOUNDEDStevenJones要求的内容。