title: Error Firebase Cloud Messaging FCM, cannot send message
body: <p>I'm using firebase cloud message trying to send a message from inside my app to a specific topic. But my program runs into "Message cannot be converted to RemoteMessage" error as shown in code below.
  I took the code from <a href="https://github.com/firebase/firebase-admin-java/blob/5ddf8fc5e5995af4758604f63197969cfad1ff76/src/test/java/com/google/firebase/snippets/FirebaseMessagingSnippets.java#L61-L74" rel="nofollow noreferrer">here</a> and <a href="https://firebase.google.anyi.in/docs/cloud-messaging/android/send-multiple?hl=fr" rel="nofollow noreferrer">here</a>, both of them are using this code but somehow it seems to run fine. </p>
  
  <p>My build.gradle:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 28
      defaultConfig {
          applicationId "com.example.firebaseteste"
          minSdkVersion 19
          targetSdkVersion 28
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation 'com.android.support:appcompat-v7:28.0.0'
      implementation 'com.android.support.constraint:constraint-layout:1.1.3'
      annotationProcessor 'com.google.firebase:firebase-core:16.0.8'
      implementation ('com.google.firebase:firebase-core:16.0.8'){
          exclude module: 'firebase-common'
      }
      annotationProcessor 'com.google.firebase:firebase-messaging:17.5.0'
      implementation ('com.google.firebase:firebase-messaging:17.5.0'){
          exclude module: 'firebase-common'
      }
      annotationProcessor 'com.google.firebase:firebase-admin:6.3.0'
      implementation 'com.google.firebase:firebase-admin:6.3.0'
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'com.android.support.test:runner:1.0.2'
      androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
  }
  
  apply plugin: 'com.google.gms.google-services'
  </code></pre>
  
  <hr>
  
  <pre><code>package com.example.firebaseteste;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.widget.Toast;
  
  import com.google.auth.oauth2.GoogleCredentials;
  import com.google.firebase.FirebaseApp;
  import com.google.firebase.FirebaseOptions;
  import com.google.firebase.messaging.FirebaseMessaging;
  import com.google.firebase.messaging.FirebaseMessagingException;
  import com.google.firebase.messaging.Message;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  
  public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          new FCMService().send();
  
      }
  
  
  
      public class FCMService  {
          public void send()  {
              try {
  
                  GoogleCredentials fromStream = GoogleCredentials.fromStream(new FileInputStream(new File("pathToFile")));
  
                  FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
                          .setConnectTimeout(10000)
                          .setCredentials(fromStream)
                          .setDatabaseUrl("database url") // you can get this from Firebase -&gt; Project settings -&gt; Service Accounts -&gt; Java
                          .build();
  
                  FirebaseApp firebaseApp = FirebaseApp.initializeApp(firebaseOptions);
  
                  FirebaseMessaging firebaseMessaging = FirebaseMessaging.getInstance();
  
                  Message message = Message.builder()
                          .putData("score", "850")
                          .putData("time", "NOW")
                          .setTopic("topic")
                          .build();
  
              //LINE WITH ERROR
              String response = firebaseMessaging.send(message);
  
  
                  System.out.println(response);
  
                  Toast.makeText(MainActivity.this, response, Toast.LENGTH_LONG);
  
  
              } catch (FirebaseMessagingException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
          }
      }
  }
  </code></pre>