Search code examples
sinch

Getting null or empty userid in Sinch


FATAL EXCEPTION: main
java.lang.IllegalArgumentException: toUserId must not be null or empty
at com.sinch.android.rtc.internal.client.calling.DefaultCallClient.call(DefaultCallClient.java:153)
at com.sinch.android.rtc.internal.client.calling.DefaultCallClient.callUser(DefaultCallClient.java:102)
at com.sinch.android.rtc.internal.client.calling.DefaultCallClient.callUser(DefaultCallClient.java:97)
at packagename.SinchService$SinchServiceInterface.callUser(SinchService.java:91)
at packagename.PlaceCallActivity.callButtonClicked(PlaceCallActivity.java:142)
at packagename.PlaceCallActivity.access$000(PlaceCallActivity.java:26)
at packagename.PlaceCallActivity$1.onClick(PlaceCallActivity.java:173)
at android.view.View.performClick(View.java:4802)
at android.view.View$PerformClick.run(View.java:20101)
at android.os.Handler.handleCallback(Handler.java:810)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:189)
at android.app.ActivityThread.main(ActivityThread.java:5532)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)

What could be the possible issues please elaborate tell. I am getting random mobile number from database using json parser request.

private void callButtonClicked() {

        try {

            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("status",status));
            params.add(new BasicNameValuePair("mobile", callNo));
            JSONObject json = jsonParser.makeHttpRequest(Config.URL_Random, "POST",
                    params);
            int success = json.getInt(TAG_SUCCESS);
            if (success == 1) {
                response=json.getString(MOBILE);
            }

        }catch (JSONException e){
            e.printStackTrace();
        }
        String userNo = response;
          Log.d("Response is",userNo);
        try {
            Call call = getSinchServiceInterface().callUser(userNo);
            if (call == null) {
                // Service failed for some reason, show a Toast and abort
                Toast.makeText(this, "Service is not started. Try stopping the service and starting it again before "
                        + "placing a call.", Toast.LENGTH_LONG).show();
                return;
            }
            String callId = call.getCallId();
            Intent callScreen = new Intent(this, CallScreenActivity.class);
            callScreen.putExtra(SinchService.CALL_ID, callId);
            startActivity(callScreen);
        } catch (MissingPermissionException e) {
            ActivityCompat.requestPermissions(this, new String[]{e.getRequiredPermission()}, 0);
        }

    }

I am storing user mobile number at login screen and callno is the number in Textview of LoggedIn No Ok. This json response response=json.getString(MOBILE); will get any random number from a database. So tell me please where i am doing it wrong and also i guess my php api made by another guy who is storing the number giving random number assured me that everything is absolutely fine from there side.


Solution

  • Try this maybe because your callNo is out of scope of callbuttonclicked Suppose if you have number in textview then you do this inside callbuttonclicked function: callNo= userNo.getText().toString();

    userNo = (TextView) findViewById(R.id.number); --> do this in onCreate method

    hope that would resolve your problem.