title: Google Cloud Functions - Client Call Error (Android Studio) :FirebaseFunctionsException: Response is not valid JSON object
body: <p>cannot execute Google Cloud Functions Android Client Call.</p>
  
  <p>I create Cloud Function from cloud console, and test works on cloud console.</p>
  
  <p>but on Android client app, it's not work.</p>
  
  <p>so, i did import Google Cloud Service Quick Start Project on my android studio, same error too.</p>
  
  <p>this is quick start project url.</p>
  
  <p><a href="https://cloud.google.com/functions/docs/quickstart-console" rel="noreferrer">https://cloud.google.com/functions/docs/quickstart-console</a></p>
  
  <p>this is my code.</p>
  
  <h1>Google Cloud Functions Call Class</h1>
  
  <pre><code>public class TestClass {
  
  private FirebaseFunctions mFunctions;
  
  public TestClass(){
      mFunctions=new FirebaseFunctions();
  }
  ..
  
  public Task&lt;String&gt; myFunc(String text) {
      // Create the arguments to the callable function, which is just one string
      Map&lt;String, Object&gt; data = new HashMap&lt;&gt;();
      data.put("message", text);
  
      return mFunctions
              .getHttpsCallable("myFunc")
              .call(data)
              .continueWith(new Continuation&lt;HttpsCallableResult, String&gt;() {
                  @Override
                  public String then(@NonNull Task&lt;HttpsCallableResult&gt; task) throws Exception {
                      // This continuation runs on either success or failure, but if the task
                      // has failed then getResult() will throw an Exception which will be
                      // propagated down.
                      String result = (String) task.getResult().getData();
                      Log.d("gcf",result);
                      return result;
                  }
              });
  }
  </code></pre>
  
  <p>}</p>
  
  <h1>in MainActivity Execute Method</h1>
  
  <pre><code>button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              TestClass testClass=new TestClass();
  
              testClass.myFunc("im bhw")
                      .addOnCompleteListener(new OnCompleteListener&lt;String&gt;() {
                          @Override
                          public void onComplete(@NonNull Task&lt;String&gt; task) {
                              if (!task.isSuccessful()) {
                                  Exception e = task.getException();
                                  if (e instanceof FirebaseFunctionsException) {
                                      FirebaseFunctionsException ffe = (FirebaseFunctionsException) e;
                                      FirebaseFunctionsException.Code code = ffe.getCode();
                                      Object details = ffe.getDetails();
                                  }
  
                                  // [START_EXCLUDE]
                                  Log.w("gcf", "myFunc:onFailure", e);
                                  Toast.makeText(getApplicationContext(),"An error occurred.",Toast.LENGTH_SHORT).show();
                                  return;
                                  // [END_EXCLUDE]
                              }
  
                              // [START_EXCLUDE]
                              String result = task.getResult();
                              Toast.makeText(getApplicationContext(),result,Toast.LENGTH_SHORT).show();
  
                              // [END_EXCLUDE]
                          }
                      });
          }
      });
  </code></pre>
  
  <h1>Google Cloud Function</h1>
  
  <pre><code>exports.myFunc = (req, res) =&gt; {
      if (req.body.message === undefined) {
          res.status(400).send('No message defined!');
      } 
      else {
          console.log(req.body.message);
          res.status(200).send('Success: ' + req.body.message);
      }
  };
  exports.myFunc = (req, res) =&gt; {
      if (req.body.message === undefined) {
      res.status(400).send('No message defined!');
      }
      else {
          console.log(req.body.message);
          res.status(200).send('Success: ' + req.body.message);
      }
  };
  </code></pre>
  
  <h1>result</h1>
  
  <pre><code>com.google.firebase.functions.FirebaseFunctionsException: Response is not valid JSON object.
      at com.google.firebase.functions.FirebaseFunctions$4.onResponse(SourceFile:296)
      at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177)
      at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
      at java.lang.Thread.run(Thread.java:761)
   Caused by: org.json.JSONException: Value &lt;!DOCTYPE of type java.lang.String cannot be converted to JSONObject
      at org.json.JSON.typeMismatch(JSON.java:111)
      at org.json.JSONObject.&lt;init&gt;(JSONObject.java:160)
      at org.json.JSONObject.&lt;init&gt;(JSONObject.java:173)
      at com.google.firebase.functions.FirebaseFunctions$4.onResponse(SourceFile:294)
      at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177) 
      at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33) 
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
      at java.lang.Thread.run(Thread.java:761) com.google.firebase.functions.FirebaseFunctionsException: Response is not valid JSON object.
      at com.google.firebase.functions.FirebaseFunctions$4.onResponse(SourceFile:296)
      at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177)
      at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
      at java.lang.Thread.run(Thread.java:761)
   Caused by: org.json.JSONException: Value &lt;!DOCTYPE of type java.lang.String cannot be converted to JSONObject
      at org.json.JSON.typeMismatch(JSON.java:111)
      at org.json.JSONObject.&lt;init&gt;(JSONObject.java:160)
      at org.json.JSONObject.&lt;init&gt;(JSONObject.java:173)
      at com.google.firebase.functions.FirebaseFunctions$4.onResponse(SourceFile:294)
      at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177) 
      at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33) 
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
      at java.lang.Thread.run(Thread.java:761) 
  </code></pre>
  
  <p>all code reffered by Firebase offical site
  <a href="https://firebase.google.com/docs/functions/callable?authuser=0" rel="noreferrer">https://firebase.google.com/docs/functions/callable?authuser=0</a></p>
  
  <p>on Cloud Console DashBoard , API Traffics catchs</p>
  
  <p>what is matter?</p>