Reputation: 2191
New to android programming. Getting Following error.
04-07 14:49:05.452: ERROR/AndroidRuntime(1566): FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94)
at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:145)
at java.lang.StringBuilder.append(StringBuilder.java:216)
at com.myapp.StartupActivity.onListItemClick(StartupActivity.java:87)
at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
at android.widget.AdapterView.performItemClick(AdapterView.java:292)
at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
at android.widget.AbsListView$1.run(AbsListView.java:3168)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Using tab layout and there are three activities for controlling tabs. I think i crossed memory heap available to my app. Can someone tell me how to destroy objects when you navigate away from tab? Error happens in following code.
String separator = "|"
String myString = "";
for(String string : Mylist)
{
myString += myString + string + separator;
}
Upvotes: 2
Views: 1654
Reputation: 42016
try String separator = "\\|"
instead String separator = "|"
there is a problem in using pipe symbol using java or you can use Pattern.quote("|")
@Qerub It's worth noting that the double-slash is only necessary if the expression string is compiled into your java code.
One slash is needed by the Java compiler so that it stores a literal slash in the expression String object. This isn't unique to regular expressions, all Java Strings compiled in the class files work this way. If you want one slash in your String in your compiled class file, type two slashes in your Java source.
If the regular expression is passed into the Java program at runtime -- via command-line arguments, or a property value -- this first slash is not necessary.
Another slash is needed by the regular expression parser so that the pipe is treated as a literal character. The expression parser doesn't care whether the string was compiled into the class file or provided at runtime.
Source code: \\|
which compiles to...
Class file: \|
now is read by regular expression parser as...
Expression parser treats as: |
While the same we used in split() then it treated as alteration, which mean string get split by every character
Source code: "query"
"query".split("|")
give result like
q
u
e
r
y
Upvotes: 1