Soru & Cevap

null pointer exception hatası alıyorum

12.06.2019 - 08:39
package com.example.proje;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

public class MainActivity extends AppCompatActivity  {
    EditText mTextaUsername;
    EditText mTextaPassword;
    Button mButtonLogin;
    Button mButtonRegister;

    FirebaseDatabase database;
  private    DatabaseReference ref;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        database = FirebaseDatabase.getInstance();
        ref=FirebaseDatabase.getInstance().getReference();

        mTextaUsername = (EditText) findViewById(R.id.txtuser);
        mTextaPassword = (EditText) findViewById(R.id.txtpass);
        mButtonLogin = (Button) findViewById(R.id.btnlog);
        mButtonRegister = (Button) findViewById(R.id.btnreg);
        mButtonRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent nt = new Intent(getApplicationContext(), Register.class);
                startActivity(nt);
            }
        });

       final   String name = mTextaUsername.getText().toString();
      final   String pass = mTextaPassword.getText().toString();


        mButtonLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                ref.child("kullanici").addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for ( DataSnapshot postSnapshot:dataSnapshot.getChildren() ) {
                 kullanici kll = postSnapshot.getValue(kullanici.class);
                int uye = Log.d("UYE", kll.getAd());


             }

                            Toast.makeText(MainActivity.this, " oturum açıldı", Toast.LENGTH_SHORT).show();
                            Intent nt = new Intent(getApplicationContext(), homapage.class);
                            startActivity(nt);


                }

                    @Override
                    public void onCancelled(@NonNull DatabaseError databaseError) {

                    }
                });

            }
            });
    }

}


 

57 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-16838-1420450309.jpg
brhngk
21.09.2019 - 12:50

Referansları ve initalize lerı kontrole diniz.