Rana Talha Tariq Rana Talha Tariq - 1 year ago 350
Android Question

DatabaseReference and FirebaseDatabase - cannot resolve symbol

I'm currently working on an institute level chat messaging application on Android. I'm using Firebase as my Cloud Server. Currently, I'm facing a

Cannot Resolve Symbol error
at the following line in my

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

I want to make chat rooms using Firebase. I know how to do this, as well as how to link Keys and Values of my Firebase Database. I also know how to update the Keys and Values from an Android Device through Firebase Cloud.

But I'm not able to resolve the
Cannot resolve Symbol error
Following is the code of my
. I'm still in initial stages of making this app.

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();

protected void onCreate(Bundle savedInstanceState) {

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);


buttonAddRoom.setOnClickListener(new View.OnClickListener() {
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.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
Entered_Username = inputUsername.getText().toString();


builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {



Answer Source

Can you please double check if you have these dependencies into your build.gradle (Module:app) file?

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

The error goes away after adding those.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download