Rana Talha Tariq Rana Talha Tariq - 2 months ago 25
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
on
DatabaseReference
and
FirebaseDatabase
at the following line in my
MainActivity
:

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

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

}
}

Answer

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.

Comments