This question has already been answered:

final VKRequest request = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS, "first_name, last_name")); ` request.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { VKApiUserFull user = ((VKList<VKApiUserFull>)response.parsedModel).getById(192644453); Log.d("User name", user.first_name + " " + user.last_name); } }); 

Returns null

 04-11 23:10:52.430 28181-28181/com.example.belzik.messagefromvk E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.belzik.messagefromvk, PID: 28181 java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.vk.sdk.api.model.VKApiUser.first_name' on a null object reference at com.example.belzik.messagefromvk.MainActivity$1$2.onComplete(MainActivity.java:90) 

But if instead of users use friends.get() , then everything is fine

  final VKRequest request = VKApi.friends().get(VKParameters.from(VKApiConst.FIELDS, "first_name"));` request.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { VKApiUserFull user = ((VKList<VKApiUserFull>)response.parsedModel).getById(192644453); Log.d("User name", user.first_name ); } }); 

Result:

 04-11 23:47:56.569 18330-18330/com.example.belzik.messagefromvk D/User name: Александр 

Reported as a duplicate by members of Pavel Mayorov , aleksandr barakin , cheops , Streletz , Mike 20 May '16 at 20:15 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • api returns an array of users, even if it was alone .. so there is not enough circulation by index 0 ...... something like user[0].first_name - Alexey Shimansky
  • It seems to me that you need to specify the id constraint in the request itself. Or do you think that the API will return all 100 million users, and they will fit into your memory? - Vladyslav Matviienko
  • I use user.getById() so I have to get a certain user from the list - kalugin1912
  • Well, if you believe the dock, then without id it executes the query by id of the current user. Probably, the current user id is not 192644453 . In the callback, asking the id of the desired user is too late, the request worked and the data came. - zRrr
  • VKApiUser user = ((VKList<VKApiUser>)response.parsedModel).get(0); will work? - Alexey Shimansky

1 answer 1

Testing here https://new.vk.com/dev/users.get Calling in java

  VKParameters parameters = new VKParameters(); parameters.put("user_ids", /*ваш id пользователя*/; VKRequest request = new VKRequest("users.get", parameters); request.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); //код обработки объекта } @Override public void onError(VKError error) { super.onError(error); } });