Problem
Using a 24-bit PNG as the backgroundImage of a view causes the app to crash on 1.7.2 on device.
Reproduction
1. Download the following image to your resources directory:
http://tothsolutions.com/logostrip.png (note: if you specify the remote image, the app will NOT crash. But if you save it locally and use that image, it will crash.)
2. Drop the following in an app.js, and run it using 1.7.2. The app will crash.
var win = Ti.UI.createWindow();
win.add(Ti.UI.createView({
top: 0, left: 0, right: 0, height: 33,
backgroundImage: 'logostrip.png'
}));
win.open();
Error Log
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): (main) [218,608] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.navtrak.navtrakmobile/com.navtrak.navtrakmobile.NavtrakActivity}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0; Titanium 1.7.2,2011/07/21 09:36,97c3689
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.navtrak.navtrakmobile/com.navtrak.navtrakmobile.NavtrakActivity}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2757)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2775)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at android.app.ActivityThread.access$2500(ActivityThread.java:130)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2121)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at android.os.Handler.dispatchMessage(Handler.java:99)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at android.os.Looper.loop(Looper.java:143)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at android.app.ActivityThread.main(ActivityThread.java:4773)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at java.lang.reflect.Method.invokeNative(Native Method)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at java.lang.reflect.Method.invoke(Method.java:521)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at dalvik.system.NativeStart.main(Native Method)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at java.util.ArrayList.get(ArrayList.java:311)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.util.TiNinePatchHelper.createChunk(TiNinePatchHelper.java:187)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.util.TiNinePatchHelper.process(TiNinePatchHelper.java:50)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.util.TiFileHelper.loadDrawable(TiFileHelper.java:320)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.util.TiFileHelper.loadDrawable(TiFileHelper.java:260)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.util.TiUIHelper.buildBackgroundDrawable(TiUIHelper.java:447)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.view.TiUIView.handleBackgroundImage(TiUIView.java:655)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.view.TiUIView.processProperties(TiUIView.java:453)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at ti.modules.titanium.ui.widget.TiView.processProperties(TiView.java:38)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:519)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:378)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:370)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.proxy.TiViewProxy.getView(TiViewProxy.java:356)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.proxy.TiViewProxy.handleAdd(TiViewProxy.java:434)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:196)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.proxy.TiWindowProxy.handleMessage(TiWindowProxy.java:100)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at ti.modules.titanium.ui.WindowProxy.handleMessage(WindowProxy.java:86)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at android.os.Handler.dispatchMessage(Handler.java:95)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.TiMessageQueue.dispatchMessage(TiMessageQueue.java:320)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.TiMessageQueue.dispatchPendingMessages(TiMessageQueue.java:304)
08-04 11:33:29.649: ERROR/TiUncaughtHandler(11597): at org.appcelerator.titanium.TiMessageQueue$2.getResult(TiMessageQueue.java:172)
For most Android devices, changing the PNG-24 to PNG-32 or to JPG resolves the issue. However, one user with a Droid X running Android 2.3.3 still receives the error below even with the image converted to a JPG. So this seems to be a larger issue than just with PNG-24's.
It seems like the picture with a black border is considered as 9-patch image... Still has this problem at 2.0.2GA.
This appears to still happen in 3.0. Any timing on a fix?
I see that this was closed as a duplicate issue. Can you point me to the issue that we should be tracking in its place?
[TIMOB-12961], which is a private ticket.
Is there any way that ticket can be made public, or at least any way we can be notified when this is scheduled to be fixed and when it actually is fixed?
PR https://github.com/appcelerator/titanium_mobile/pull/3939
One of us will post here when that ticket is resolved. There's a PR open for it already. https://github.com/appcelerator/titanium_mobile/pull/3939
The ticket was resolved and verified.
Thanks Dawson. Will the fix be in 3.1 or a different sdk version?
3.1.0.
Closing ticket as duplicate.