NullPointerException on ContactsManager

30 views
Skip to first unread message

jugraj...@gmail.com

unread,
Oct 12, 2016, 1:32:50 AM10/12/16
to CodenameOne Discussions
Sir I am developing app that help me use a web service to sent sms via internet
the problem I am facing is that when i test it on device simulator. the button action for contact button works fine.
But when i send the built for android i get a apk in which on clicking contact button i got null pointer error
can you tell me what i am doing wrong as for my testing side i.e. on PC it work fine but on actual device it gives error.

If you are experiencing an issue please mention the full platform your issue applies to:
IDE: IDEA
Desktop OS: Ubuntu
Simulator: Default
Device: Android 6.0

Chen Fishbein

unread,
Oct 12, 2016, 2:18:39 AM10/12/16
to CodenameOne Discussions
Please connect the device with cable to the pc and provide the full stacktrace with the android ddms tool.

Jugraj Singh

unread,
Oct 12, 2016, 4:10:46 AM10/12/16
to codenameone...@googlegroups.com
On Wed, Oct 12, 2016 at 11:48 AM, Chen Fishbein <cf2...@gmail.com> wrote:
> Please connect the device with cable to the pc and provide the full
> stacktrace with the android ddms tool.
>
How to do so please tell.
I am unable to get the trace

--

Jugraj Singh

git :- https://github.com/jugrajsingh
blog :- ezecodes.wordpress.com

"If all you have is a hammer, everything looks like a nail"

Chen Fishbein

unread,
Oct 12, 2016, 4:46:52 AM10/12/16
to CodenameOne Discussions
Install the android sdk or android studio connect the device with cable and look at the log:


You will need to enable your device for debugging if it's not in dev mode:

Jugraj Singh

unread,
Oct 12, 2016, 6:19:40 AM10/12/16
to codenameone...@googlegroups.com
Here is the log i get.
Also there is a link to the apk install and try it you will get the error.
https://github.com/jugrajsingh/Messenger/releases/download/0.1/Messenger.apk
log.txt

Shai Almog

unread,
Oct 12, 2016, 9:44:38 PM10/12/16
to CodenameOne Discussions
See this from your log:
java.lang.NullPointerException: value == null
10-12 15:32:08.991: W/System.err(21384): 	at java.util.Hashtable.put(Hashtable.java:362)
10-12 15:32:08.991: W/System.err(21384): 	at userclasses.StateMachine.onMain_ButtonAction(StateMachine.java:75)

Check out line 75...

Jugraj Singh

unread,
Oct 13, 2016, 5:49:08 AM10/13/16
to codenameone...@googlegroups.com
This is the code around line 75
73 for (String phoneContact : phoneContacts) {
74 Contact contact = Display.getInstance().getContactById(phoneContact);
75 Hashtable<String, String> temp = new Hashtable<>();
76 temp.put("phone",contact.getPrimaryPhoneNumber());
77 temp.put("name",contact.getDisplayName());
78 con.add(temp);
79 }

I did not see anything wrong there.

Jugraj Singh

unread,
Oct 13, 2016, 5:51:01 AM10/13/16
to codenameone...@googlegroups.com
On Thu, Oct 13, 2016 at 3:18 PM, Jugraj Singh <jugraj...@gmail.com> wrote:
<snip>
>
> This is the code around line 75
> 73 for (String phoneContact : phoneContacts) {
> 74 Contact contact = Display.getInstance().getContactById(phoneContact);
> 75 Hashtable<String, String> temp = new Hashtable<>();
> 76 temp.put("phone",contact.getPrimaryPhoneNumber());
> 77 temp.put("name",contact.getDisplayName());
> 78 con.add(temp);
> 79 }
>
> I did not see anything wrong there.
>
The exception i getting is null pointer value == null but i initialise
the temp variable here.

Shai Almog

unread,
Oct 13, 2016, 11:21:18 PM10/13/16
to CodenameOne Discussions
I'm guessing you changed the lines a bit since the stack points at passing a null to the put method which means that either display name is null or the primary phone number is null.
You need to account for cases when these are null.
Reply all
Reply to author
Forward
0 new messages