简体   繁体   English

Android中字符串变量的最大长度

[英]Max length of a string variable in Android

There seems to be a max length to how many chars a string can hold. 一个字符串可以容纳多少个字符似乎有一个最大长度。 In my case it's being populated with HTML via JSON and at around 1500 chars it crashes. 在我的情况下,它是通过JSON填充HTML的,并且在1500个字符左右时崩溃了。

There are no special characters in the text apart from HTML. 除HTML外,文本中没有特殊字符。

Is there a way around this or is that it? 有没有解决的办法?

Cheers, 干杯,

Mike. 麦克风。

The maximums (both practical and theoretical) are far higher. 最大值(实际值和理论值)都更高。 Theoretically, it's 2^31 - 1 characters. 理论上,它是2 ^ 31-1个字符。 In practice, you'll be limited to available memory, but even on a mobile system you'll have more than 1.5KB. 实际上,您将只能使用可用内存,但是即使在移动系统上,您也将拥有超过1.5KB的内存。

You have a different issue. 您有其他问题。 Use JSON Lint to first check that you have valid JSON. 使用JSON Lint首先检查您是否具有有效的JSON。

Its the same as what Java offers. 它与Java提供的功能相同。 If I understand your question correctly, you are trying to read HTML data (as JSON) from a service and it is crashing after receiving certain response. 如果我正确理解了您的问题,则您正在尝试从服务读取HTML数据(作为JSON),并且在收到某些响应后崩溃。 If that is the case, try if the same operation works from your browser or through simple HTML form. 如果是这种情况,请尝试通过浏览器或简单的HTML表单执行相同的操作。

Elsewhere in Stack Overflow there are mentions of a size limit on ArrayAdapter content. 在堆栈溢出的其他地方,提到了ArrayAdapter内容的大小限制。 This may be your problem, not XML or Java strings in general. 这可能是您的问题,而不是一般的XML或Java字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM