DatabaseReference and FirebaseDatabase - cannot resolve character

I am currently working on institute-level chat sharing apps on Android. I use Firebase as a cloud server. Currently, I have encountered Cannot Resolve Symbol error on DatabaseReference and FirebaseDatabase in the following line in MainActivity :

 private DatabaseReference root = FirebaseDatabase.getInstance().getReference().getRoot(); 

I want chats to use Firebase. I know how to do this, as well as how to bind the keys and values ​​of my Firebase database. I also know how to update keys and values ​​from an Android device through Firebase Cloud.

But I can not resolve Cannot Resolve Symbol error . Below is the code for my MainActivity . I'm still in the early stages of creating this application.

  package com.ranatalha.realtimechat; import android.content.DialogInterface; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { private Button buttonAddRoom; private EditText editTextAddaChatRoom; private ListView listViewChatRooms; private ArrayAdapter<String> arrayAdapter; private ArrayList<String> list_of_rooms = new ArrayList<>(); private String Entered_Username; private DatabaseReference root = FirebaseDatabase.getInstance().getReference().getRoot(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); buttonAddRoom = (Button) findViewById(R.id.buttonAddRoom); editTextAddaChatRoom = (EditText) findViewById(R.id.editTextAddaChatRoom); listViewChatRooms = (ListView) findViewById(R.id.listViewChatRooms); //************Creation of an array list to store the list of active chat rooms************ arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, list_of_rooms); listViewChatRooms.setAdapter(arrayAdapter); //***************************************************************************************** request_user_name(); buttonAddRoom.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { } }); } private void request_user_name(){ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Enter Your Name:"); final EditText inputUsername = new EditText(this); builder.setView(inputUsername); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Entered_Username = inputUsername.getText().toString(); } }); builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.cancel(); request_user_name(); } }); builder.show(); } } 
+8
android firebase firebase-database
source share
2 answers

Can you double check if you have these dependencies in the build.gradle file (Module: app)?

 compile 'com.google.firebase:firebase-core:11.4.0' compile 'com.google.firebase:firebase-database:11.4.0' 

After adding this error, the error disappears.

+20
source share

You need to add these dependencies to your

1) build.gradle (module: application).

 implementation 'com.google.firebase:firebase-database:11.6.2' 

2) build.gradle (top level build)

 classpath 'com.google.gms:google-services:3.1.0' 

3) add google-services.json to the application module in Android Studio

0
source share

All Articles