java.lang.NullPointerException

Appcelerator JIRA | Andreas | 6 years ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    h2. Problem Multi-string i18n substitution (demonstrated in [#Test case 2] and [#Test case 3]) using String.format() fails, while single string substitution ([#Test case 1]) works as expected. {panel} Note that the project must be manually cleaned after any strings.xml files have been modified {panel} h2. Test case h3. Test case 1 * Single string, non-positional substitution works as expected * Single string, positional substitution works as expected {code:lang=javascript|title=app.js} Ti.API.info('The result of the string substitution is: ' + String.format(L('nonPositionalSubstitutionOneString'), 'String1')); Ti.API.info('The result of the string substitution is: ' + String.format(L('positionalSubstitutionOneString'), 'String1')); {code} {code:lang=xml|title=i18n/en/strings.xml} <?xml version="1.0" encoding="UTF-8"?> <resources> <string name="nonPositionalSubstitutionOneString">%s</string> <string name="positionalSubstitutionOneString">%1$s</string> </resources> {code} {code:lang=none|title=logcat} 883 TiAPI I The result of the string substitution is: String1 883 TiAPI I The result of the string substitution is: String1 {code} h2. Test case 2 * Multiple string, non-positional substitution fails {code:lang=javascript|title=app.js} Ti.API.info('The result of the string substitution is: ' + String.format(L('nonPositionalSubstitutionThreeString'), 'String1', 'String2', 3)); {code} {code:lang=xml|title=i18n/en/strings.xml} <?xml version="1.0" encoding="UTF-8"?> <resources> <string name="nonPositionalSubstitutionThreeString">%s %s %d</string> </resources> {code} {code:lang=none|title=console} [ERROR] Error generating R.java from manifest [ERROR] /home/appcel/Titanium Studio Workspace/testing10/build/android/res/values/strings.xml:3: error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute? [ERROR] /home/appcel/Titanium Studio Workspace/testing10/build/android/res/values/strings.xml:3: error: Unexpected end tag string {code} {code:lang=none|title=logcat} 909 TitaniumModule E (KrollRuntimeThread) [248,1369] Error in string format 909 TitaniumModule E java.lang.NullPointerException 909 TitaniumModule E at ti.modules.titanium.TitaniumModule.stringFormat(TitaniumModule.java:285) 909 TitaniumModule E at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method) 909 TitaniumModule E at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:107) 909 TitaniumModule E at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:207) 909 TitaniumModule E at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:127) 909 TitaniumModule E at android.os.Handler.dispatchMessage(Handler.java:95) 909 TitaniumModule E at android.os.Looper.loop(Looper.java:123) 909 TitaniumModule E at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:102) 909 TiAPI I The result of the string substitution is: null {code} h2. Test case 3 * Multiple string, positional substitution fails {code:lang=javascript|title=app.js} Ti.API.info('The result of the string substitution is: ' + String.format(L('positionalSubstitutionThreeString'), 'String1', 'String2', 3)); {code} {code:lang=xml|title=i18n/en/strings.xml} <string name="positionalSubstitutionThreeString">%3$d %2$s %1$s</string> {code} No error produced in console. {code:lang=none|title=logcat} 983 TitaniumModule E (KrollRuntimeThread) [280,1472] Error in string format 983 TitaniumModule E java.lang.NullPointerException 983 TitaniumModule E at ti.modules.titanium.TitaniumModule.stringFormat(TitaniumModule.java:285) 983 TitaniumModule E at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method) 983 TitaniumModule E at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:107) 983 TitaniumModule E at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:207) 983 TitaniumModule E at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:127) 983 TitaniumModule E at android.os.Handler.dispatchMessage(Handler.java:95) 983 TitaniumModule E at android.os.Looper.loop(Looper.java:123) 983 TitaniumModule E at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:102) 983 TiAPI I The result of the string substitution is: null {code} h2. Discussions The original reporter prompted the above investigation, and provided the following information about Titanium 1.7.X where there was a slightly different message {code} * Titanium SDK version: 1.7.2 * Platform & version: Android 2.3 * Device Details: Android emulator * Host Operating System: Windows Vista * Titanium Studio version: Titanium Studio, build: 1.0.2.201107130739 {code} {code} If i use % placeholder inside the language strings, the building is stopped! If i remove the %, everything works like expected The following configuration of my string.xml dont work! <?xml version="1.0" encoding="UTF-8"?> <resources> <string name="gpUiPageIntOfInt">Page %d of %d</string> </resources> This is the output in my adb log. The errormessage is *{{"Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?"}}* [DEBUG] D:\development\enviroment\Android\android-sdk\platform-tools\aapt.exe package -m -J D:\development\workspaces\titanium-studio\meintest\build\android\gen -M D:\development\workspaces\titanium-studio\meintest\build\android\AndroidManifest.xml -S D:\development\workspaces\titanium-studio\meintest\build\android\res -I D:\development\enviroment\Android\android-sdk\platforms\android-7\android.jar [ERROR] D:\development\workspaces\titanium-studio\meintest\build\android\res\values\strings.xml:23: error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute? [ERROR] D:\development\workspaces\titanium-studio\meintest\build\android\res\values\strings.xml:23: error: Unexpected end tag string [ERROR] Error generating R.java from manifest {code} h2. Workaround See [this stackoverflow.com thread|http://stackoverflow.com/questions/4414389/android-xml-percent-symbol/4417333#4417333] Use {{formatted="false"}} for each element of the {{strings.xml}} file where multiple placeholders are used. Works as expected on Android 2.2+ & Titanium SDK version: 2.0.0 (03/15/12 07:02 c822d01). h3. Test Case 4 {code:lang=xml|title=/i18n/en/strings.xml} <?xml version="1.0" encoding="UTF-8"?> <resources> <string name="phrase" formatted="false">You say %2$s and I say %1$s!</string> <string name="greeting">hello</string> <string name="signoff">goodbye</string> </resources> {code} {code:lang=javascript|title=app.js} var i18nError = '<no translation available for the current system locale>'; Ti.API.info(String.format(L('phrase'), L('greeting', i18nError), L('signoff', i18nError))); {code}

    Appcelerator JIRA | 6 years ago | Andreas
    java.lang.NullPointerException

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at ti.modules.titanium.TitaniumModule.stringFormat()
    2. ti.modules.titanium
      TitaniumModule.stringFormat
      1. ti.modules.titanium.TitaniumModule.stringFormat(TitaniumModule.java:285)
      1 frame
    3. org.appcelerator.kroll
      V8Runtime.handleMessage
      1. org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
      2. org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:107)
      3. org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:207)
      4. org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:127)
      4 frames
    4. Android Platform
      Looper.loop
      1. android.os.Handler.dispatchMessage(Handler.java:95)
      2. android.os.Looper.loop(Looper.java:123)
      2 frames
    5. org.appcelerator.kroll
      KrollRuntime$KrollRuntimeThread.run
      1. org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:102)
      1 frame