[TIMOB-3262] Android: Contact Email and Phone Throw "Cannot find default value for object" When Stringified
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2017-06-12T18:28:16.000+0000 |
Affected Version/s | Release 1.7.0, Release 3.0.0 |
Fix Version/s | n/a |
Components | Android |
Labels | api |
Reporter | Dawson Toth |
Assignee | Ingo Muschenetz |
Created | 2011-04-15T03:40:42.000+0000 |
Updated | 2017-06-12T18:28:16.000+0000 |
Description
Problem
Assume that we have a "person" variable returned from calling Ti.Contacts.showContacts({ selectedPerson: ... }) call. If you do something to turn person.email.work into a string such as 'Work: ' + person.email.work, the "Cannot find default value for object" error is displayed.
Kroll attempts to access person.email.home, which is an ArrayList (ref: https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/contacts/src/ti/modules/titanium/contacts/PersonProxy.java#L69"> PersonProxy.java#69). It doesn't know how to turn this into a string, so the error is displayed.
Solution
The real problem here is that we get a very obtuse error message when you try to do something common (print out a variable for debugging purposes). If we could receive an actual array from person.email.home, it could be stringified into its values, and this problem would be avoided entirely.
Sample Code
var win = Titanium.UI.createWindow({
backgroundColor:'#fff'
});
var label = Ti.UI.createLabel({
top: 0, right: 0, bottom: 70, left: 0,
text: 'Pick Someone With a "Home" Email, and you should receive an error message "Cannot find default value for object".'
});
win.add(label);
var button = Ti.UI.createButton({
title: 'Show Contacts',
bottom: 20,
width: 200,
height: 40
});
button.addEventListener('click', function() {
Titanium.Contacts.showContacts({
selectedPerson: function(e) {
alert(String(e.person.email.home)); // this will throw the "cannot find default value for object" error
// and the .length call below will have problems if the person doesn't have any home email addresses
for (var i = 0, l = e.person.email.home.length; i < l; i++) {
alert(i + ': ' + e.person.email.home[i]);
}
}
});
});
win.add(button);
win.open();
Steps to Reproduce
- Drop the above into an app.js
- Launch it and touch the "Show Contacts" button.
- Pick someone who has an email address with the "Home"
type
- You'll see the error
Trace Level Log
I/ActivityManager( 2456): Displayed activity com.android.contacts/.ContactsListActivity: 779 ms (total 779 ms)
V/WindowManager( 2456): Dsptch > Window{4823c0f8 com.android.contacts/com.android.contacts.ContactsListActivity paused=false}
V/InputDevice( 2456): ID[0]=0(0) Dn(0=>1)
V/WindowManager( 2456): Dsptch > Window{4823c0f8 com.android.contacts/com.android.contacts.ContactsListActivity paused=false}
V/InputDevice( 2456): ID[0]=0(0) Up(1=>0)
I/ContactsListActivity(24230): uri is content://com.android.contacts/contacts/lookup/3521i25c61c248f9cab48.1998r770-2C2C4E484652484E52484E34424248/529
D/ContactsListActivity(24230): onPause------------------------------------------
I/TiRootActivity(21253): (main) [0,0] checkpoint, on root activity resume. context = org.appcelerator.titanium.TiContext@47cf94c0
E/KrollCallback(21253): (kroll$1: app://app.js) [111,111] ECMA Error evaluating source, invocation: [callMethod (anonymous) org.appcelerator.titanium.kroll.KrollCallback@47caeb98], message: TypeError: Cannot find default value for object. (file:///android_asset/Resources/app.js#19)
E/KrollCallback(21253): org.mozilla.javascript.EcmaError: TypeError: Cannot find default value for object. (file:///android_asset/Resources/app.js#19)
E/KrollCallback(21253): at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3761)
E/KrollCallback(21253): at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3739)
E/KrollCallback(21253): at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3767)
E/KrollCallback(21253): at org.mozilla.javascript.ScriptRuntime.typeError1(ScriptRuntime.java:3779)
E/KrollCallback(21253): at org.mozilla.javascript.ScriptableObject.getDefaultValue(ScriptableObject.java:839)
E/KrollCallback(21253): at org.mozilla.javascript.ScriptableObject.getDefaultValue(ScriptableObject.java:758)
E/KrollCallback(21253): at org.mozilla.javascript.NativeArray.getDefaultValue(NativeArray.java:522)
E/KrollCallback(21253): at org.mozilla.javascript.ScriptRuntime.toString(ScriptRuntime.java:790)
E/KrollCallback(21253): at org.mozilla.javascript.NativeString.execIdCall(NativeString.java:259)
E/KrollCallback(21253): at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:129)
E/KrollCallback(21253): at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1711)
E/KrollCallback(21253): at script(file:///android_asset/Resources/app.js:19)
E/KrollCallback(21253): at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
E/KrollCallback(21253): at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
E/KrollCallback(21253): at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
E/KrollCallback(21253): at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3161)
E/KrollCallback(21253): at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
E/KrollCallback(21253): at org.appcelerator.titanium.kroll.KrollCallback.callSync(KrollCallback.java:139)
E/KrollCallback(21253): at org.appcelerator.titanium.kroll.KrollCallback$1.run(KrollCallback.java:164)
E/KrollCallback(21253): at android.os.Handler.handleCallback(Handler.java:587)
E/KrollCallback(21253): at android.os.Handler.dispatchMessage(Handler.java:92)
E/KrollCallback(21253): at android.os.Looper.loop(Looper.java:123)
E/KrollCallback(21253): at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:89)
E/TiJSError(21253): (kroll$1: app://app.js) [4,115] ----- Titanium Javascript Runtime Error -----
E/TiJSError(21253): (kroll$1: app://app.js) [1,116] - In file:///android_asset/Resources/app.js:19,0
E/TiJSError(21253): (kroll$1: app://app.js) [0,116] - Message: TypeError: Cannot find default value for object. (file:///android_asset/Resources/app.js#19)
E/TiJSError(21253): (kroll$1: app://app.js) [0,116] - Source: null
Tested On
Titanium SDK version: 1.6.0 (02/23/11 12:34 9882e81)
Titanium SDK version: 1.7.0 (03/03/11 10:45 87a2113...)
BROKEN on Android Emulator 2.2 APIs
BROKEN on Android Device Epic 4G 2.2
Associated Helpdesk Ticket
http://developer.appcelerator.com/helpdesk/view/76227">http://developer.appcelerator.com/helpdesk/view/76227
My "alert(String(e.person.email.home));" example is a bit obtuse; you could instead imagine the user doing "Ti.API.info('MyApp :: Contacts :: Receive email back, with home: ' + e.person.home)" and receiving the cryptic problem I have created this issue to resolve.
Putting in 1.7.0 bucket to try and have it solved in that timeframe.
Not sure if I am reproducing this problem correctly or not, but this is what I get:
Tested on a Samsung Galaxy S2 using TiSDK 2.2.0v20120904101713.
The issue cannot reproduce with the release master 3.2.0 Tested with: Titanium Studio, build: 2.1.2.201208301612 Titanium SDK version: 3.2.0 Tested on Device: Samsung galaxy s duos Android version: 4.0.4
Closing ticket with reference to the above comments.