-1

iv'e been stuck for hours trying to figure out what's the problem... every time I try to access the reference the up crushes. tried to open like 5 new projects and firebases....

MainActivity( only realated stuff):

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private Button ba;
    FirebaseDatabase database;
    DatabaseReference myRef;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ba=findViewById(R.id.ba);
        ba.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        if(view==ba)
        {
           database = FirebaseDatabase.getInstance();
            myRef=database.getReference("Foods"); //this is where it crushes
           // myRef.setValue("ba");
        }

    }

}

The Run Log:

E/RunLoop: Uncaught exception in Firebase Database runloop (3.0.0). Please report to firebase-database-client@google.com
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp$IdTokenListener;
        at com.google.firebase.database.android.AndroidPlatform.newAuthTokenProvider(com.google.firebase:firebase-database@@16.0.4:112)
        at com.google.firebase.database.core.Context.ensureAuthTokenProvider(com.google.firebase:firebase-database@@16.0.4:246)
        at com.google.firebase.database.core.Context.initServices(com.google.firebase:firebase-database@@16.0.4:98)
        at com.google.firebase.database.core.Context.freeze(com.google.firebase:firebase-database@@16.0.4:77)
        at com.google.firebase.database.core.RepoManager.createLocalRepo(com.google.firebase:firebase-database@@16.0.4:92)
        at com.google.firebase.database.core.RepoManager.createRepo(com.google.firebase:firebase-database@@16.0.4:42)
        at com.google.firebase.database.FirebaseDatabase.ensureRepo(com.google.firebase:firebase-database@@16.0.4:357)
        at com.google.firebase.database.FirebaseDatabase.getReference(com.google.firebase:firebase-database@@16.0.4:201)
        at com.example.caloriccalcyair1.MainActivity.onClick(MainActivity.java:43)
        at android.view.View.performClick(View.java:7869)
        at android.widget.TextView.performClick(TextView.java:14958)
        at android.view.View.performClickInternal(View.java:7838)
        at android.view.View.access$3600(View.java:886)
        at android.view.View$PerformClick.run(View.java:29362)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8016)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.FirebaseApp$IdTokenListener" on path: DexPathList[[zip file "/data/app/com.example.caloriccalcyair1-mv4wi0pKnsqKEHcy89c_hA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.caloriccalcyair1-mv4wi0pKnsqKEHcy89c_hA==/lib/arm64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.google.firebase.database.android.AndroidPlatform.newAuthTokenProvider(com.google.firebase:firebase-database@@16.0.4:112) 
        at com.google.firebase.database.core.Context.ensureAuthTokenProvider(com.google.firebase:firebase-database@@16.0.4:246) 
        at com.google.firebase.database.core.Context.initServices(com.google.firebase:firebase-database@@16.0.4:98) 
        at com.google.firebase.database.core.Context.freeze(com.google.firebase:firebase-database@@16.0.4:77) 
        at com.google.firebase.database.core.RepoManager.createLocalRepo(com.google.firebase:firebase-database@@16.0.4:92) 
        at com.google.firebase.database.core.RepoManager.createRepo(com.google.firebase:firebase-database@@16.0.4:42) 
        at com.google.firebase.database.FirebaseDatabase.ensureRepo(com.google.firebase:firebase-database@@16.0.4:357) 
        at com.google.firebase.database.FirebaseDatabase.getReference(com.google.firebase:firebase-database@@16.0.4:201) 
        at com.example.caloriccalcyair1.MainActivity.onClick(MainActivity.java:43) 
        at android.view.View.performClick(View.java:7869) 
        at android.widget.TextView.performClick(TextView.java:14958) 
        at android.view.View.performClickInternal(View.java:7838) 
        at android.view.View.access$3600(View.java:886) 
        at android.view.View$PerformClick.run(View.java:29362) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:237) 
        at android.app.ActivityThread.main(ActivityThread.java:8016) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076) 

i followed the firebase installation step by step and verifyed the project. also added the firebase to the porject with the Tools option, so everything should be ok

image of the firebase database

MohanKumar
  • 960
  • 10
  • 26
  • Please check this out. It seems like a same issue. https://stackoverflow.com/questions/39825543/didnt-find-class-com-google-firebase-provider-firebaseinitprovider – Akash Chaudhary Jul 16 '20 at 17:39

1 Answers1

0

Instead of using your code. Try using this:


database = FirebaseDatabase.getInstance().getReference().child("Foods");

And also try wrapping your on click listener like this inside onCreate

button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                    ...    
                    }
});
  • same problem :( – Yair Teperberg Jul 16 '20 at 18:12
  • @YairTeperberg There are multiple problems that you're dealing with here.. You do not need to implement View.onClickListner class in order to implement a click listner. It also depends where you are using the click listner. How you are using the firebase references. Is your grade file setup properly.. There can be a lot of scenarios.. I can share an example code if you'd like. – Avishake Adhikary Jul 16 '20 at 18:27
  • first of all thanks. i'd love to! im still trying to figure out the problem and it could help/ – Yair Teperberg Jul 16 '20 at 18:31
  • @YairTeperberg I'm sorry I don't have any simple code that I can send sample about, I only have bigger projects, and that might confuse you even more. I have this link to a website they share tutorials, check them out https://www.tutorialspoint.com/firebase/firebase_read_data.htm – Avishake Adhikary Jul 16 '20 at 18:37
  • @YairTeperberg Also make sure everything you're dealing with is setup correctly and you're using the latest code snippets and methods that your gradle consists of. (As code might change depending on the version of the framework you're using). – Avishake Adhikary Jul 16 '20 at 18:41