无法在com.example.sdl.change_password的child()中将参数'pathString'传递为null。<init>(change_password.java:30)

时间:2019-09-29 21:10:47

标签: java android firebase

已经尝试过类似问题的所有答案,但无法解决问题,请提供此代码的指导。

我正在尝试将内容从一个活动传递到另一个活动;内容已传递,但ref.child(domain)中的change_password无法获取路径。

打包com.example.sdl;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

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 {

    private Button Login;
     EditText domain,pass,subdomain,profession,branch,rollno;
    FirebaseDatabase database=FirebaseDatabase.getInstance();
  public  String sdomain,ssubdomain,sprofession,sbranch,srollno,spass;


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

        Login=(Button) findViewById(R.id.Login);

        domain = (EditText) findViewById((R.id.domain));
        pass=(EditText)findViewById(R.id.pass);
        subdomain = (EditText)findViewById(R.id.subdomain);
        profession = (EditText)findViewById(R.id.profession);
        branch = (EditText)findViewById(R.id.branch);
        rollno = (EditText)findViewById(R.id.rollno);



        Login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                openadmin();
            }
        });




    }

    public void openadmin(){


            sdomain=domain.getText().toString();
            ssubdomain=subdomain.getText().toString();
            sprofession=profession.getText().toString();
            sbranch=branch.getText().toString();
            srollno=rollno.getText().toString();
            spass=pass.getText().toString();

        DatabaseReference ref=database.getReference().child(sdomain).child(ssubdomain).child(sprofession).child(sbranch).child(srollno);

        ref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                String saved_pass= dataSnapshot.child("password").getValue().toString();

                if (sprofession.equals("admin")) {

                    if (saved_pass.equals(spass)) {
                        open_admin();
                    } else {
                        Toast.makeText(MainActivity.this, "PASSWORD IS WRONG", Toast.LENGTH_SHORT).show();
                    }
                }
                if (sprofession.equals("student")){

                        if (saved_pass.equals(spass)) {
                            open_student();

                        }
                        else{
                            Toast.makeText(MainActivity.this, "PASSWORD IS WRONG", Toast.LENGTH_SHORT).show();
                        }
                }


            }

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

                Toast.makeText(MainActivity.this, "NO USER FOUND", Toast.LENGTH_SHORT).show();

            }
        });



    }
    public void  open_admin(){
        Intent login = new Intent(this, main_admin.class);
        startActivity(login);
    }
    public void open_student(){
        Intent login =new Intent(this, Student.class);
        login.putExtra("domain",sdomain);
        login.putExtra("subdomain",ssubdomain);
        login.putExtra("profession",sprofession);
        login.putExtra("branch",sbranch);
        login.putExtra("rollno",srollno);
        login.putExtra("pass",spass);
         startActivity(login);
    }
}


package com.example.sdl;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class Student extends AppCompatActivity {

    TextView student_text;
    Button change_pass;
    String sdomain,ssubdomain,sprofession,sbranch,srollno,spass;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_student);

       student_text= (TextView) findViewById(R.id.student_text);


        change_pass=(Button) findViewById(R.id.change_pass);

        Toast.makeText(this, ssubdomain, Toast.LENGTH_SHORT).show();
        change_pass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                change_pass();

            }
        });

    }

         public  void change_pass(){


             sdomain=getIntent().getExtras().getString("domain");
             ssubdomain=getIntent().getExtras().getString("subdomain");
             sprofession=getIntent().getExtras().getString("profession");
             sbranch=getIntent().getExtras().getString("branch");
             srollno=getIntent().getExtras().getString("rollno");
             spass=getIntent().getExtras().getString("pass");
            Intent change = new Intent(this,changepass.class);
             change.putExtra("domain",sdomain);
             change.putExtra("subdomain",ssubdomain);
             change.putExtra("profession",sprofession);
             change.putExtra("branch",sbranch);
             change.putExtra("rollno",srollno);
             change.putExtra("pass",spass);
             startActivity(change);

    }
}
package com.example.sdl;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.google.firebase.database.FirebaseDatabase;

public class changepass extends AppCompatActivity {

    FirebaseDatabase database=FirebaseDatabase.getInstance();


        EditText oldpass,newpass;
        Button changepas;
        String sdomain,ssubdomain,sprofession,sbranch,srollno,spass;

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


             oldpass= (EditText)findViewById(R.id.oldpass);
            newpass=(EditText)findViewById(R.id.newpass);
            changepas= (Button) findViewById(R.id.changepas);

        changepas.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                verify_change();

            }
        });

    }

        public void  verify_change(){



            final String voldpass=oldpass.getText().toString();
             final String vnewpass=newpass.getText().toString();

            sdomain=getIntent().getExtras().getString("domain");
            ssubdomain=getIntent().getExtras().getString("subdomian");
            sprofession=getIntent().getExtras().getString("profession");
            sbranch=getIntent().getExtras().getString("branch");
            srollno=getIntent().getExtras().getString("rollno");
            spass=getIntent().getExtras().getString("pass");

            change_password cp= new change_password(sdomain,ssubdomain,sprofession,sbranch,srollno,spass,vnewpass,voldpass);


        }

}

package com.example.sdl;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class change_password {

    FirebaseDatabase database=FirebaseDatabase.getInstance();


    private  String domain;
    private String subdomain,profession,branch,rollno,pass,newpass,oldpass;

    public change_password() {
    }

    public change_password( String domain,  String subdomain,  String profession,  String branch,  String rollno,  String pass,  String newpass,  String  oldpass) {
        this.domain = domain;
        this.subdomain = subdomain;
        this.profession = profession;
        this.branch = branch;
        this.rollno = rollno;
        this.pass = pass;
        this .newpass=newpass;
        this.oldpass=   oldpass;

        DatabaseReference ref=database.getReference();


      ref.child(domain).child(subdomain).child(profession).child(branch).child(rollno).child("password").setValue(newpass);
    }




    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getSubdomain() {
        return subdomain;
    }

    public void setSubdomain(String subdomain) {
        this.subdomain = subdomain;
    }

    public String getProfession() {
        return profession;
    }

    public void setProfession(String profession) {
        this.profession = profession;
    }

    public String getBranch() {
        return branch;
    }

    public void setBranch(String branch) {
        this.branch = branch;
    }

    public String getRollno() {
        return rollno;
    }

    public void setRollno(String rollno) {
        this.rollno = rollno;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getNewpass() {
        return newpass;
    }

    public void setNewpass(String newpass) {
        this.newpass = newpass;
    }

    public String getOldpass() {
        return oldpass;
    }

    public void setOldpass(String oldpass) {
        this.oldpass = oldpass;
    }
}

0 个答案:

没有答案