-1

I have the following crash

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1010, result=-1, data=Intent {  launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 }(has extras) }} to activity {com.forsale.forsale/com.forsale.forsale.view.ItemsActivity}: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 1
},
^
at android.app.ActivityThread.deliverResults(ActivityThread.java:4472)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4515)
at android.app.ActivityThread.-wrap22(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1687)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 1
},
^
at java.util.regex.Pattern.compileImpl(Native Method)
at java.util.regex.Pattern.compile(Pattern.java:1340)
at java.util.regex.Pattern.<init>(Pattern.java:1324)
at java.util.regex.Pattern.compile(Pattern.java:946)
at java.lang.String.split(String.java:2325)
at java.lang.String.split(String.java:2367)
at com.forsale.forsale.view.ItemsActivity.preserveAttributes(ItemsActivity.java:1449)
at com.forsale.forsale.view.ItemsActivity.onActivityResult(ItemsActivity.java:1148)
at android.app.Activity.dispatchActivityResult(Activity.java:7256)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4468)

my code is as following :

String[] items = attributes.split("},");
Amira Elsayed Ismail
  • 9,216
  • 30
  • 92
  • 175

1 Answers1

4

split function take as argument a regex pattern (as it is written in the errors)

}is a special character for regex

try to escape it like that

   String[] items = attributes.split("\\},");
CharybdeBE
  • 1,791
  • 1
  • 20
  • 35
  • Did not need to escape it trying this on eclipse : `String a = "hell},o"; String[] items = a.split("},"); System.out.println(items[0]);` output was "hell" – Logan Wlv Aug 01 '18 at 12:34
  • Yes indeed but it is perhaps due to Java version (in the error logs of the OP we see that he use Java to make android app which may have an impact of the choice of JDK) – CharybdeBE Aug 02 '18 at 12:06