0

I hope you doing well so im facing problem when i run this code im trying get data from my realtime database to this page profile page but its not working

public class Adopter_Profile extends AppCompatActivity {


EditText up_phone,up_email;
TextView ud_name;
Button btn_update;
String displayname=null;
DatabaseReference rootrefb;
DatabaseReference userref;
FirebaseDatabase data;
private  final String TAG=this.getClass().getName().toUpperCase();//here th problem !!!!!

private static final String Adopters ="Adopters";

Intent intent = getIntent();
String adoemail = intent.getStringExtra("adoemail");

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_adopter__profile);
    up_phone=(EditText)findViewById(R.id.profilphone);
    ud_name=(TextView) findViewById(R.id.profilename);
    btn_update=(Button) findViewById(R.id.profileUpdate);
    //data=FirebaseDatabase.getInstance();
   // adopterref= data.getReference().child("Adopters");
    DatabaseReference rootrefb=FirebaseDatabase.getInstance().getReference();
    DatabaseReference userref= rootrefb.child(Adopters);

    Log.v("EMAILADD",userref.orderByChild("adoemail").equalTo(adoemail).toString());
   // Log.d(TAG, "onCreate: "+adoname+ " "+adophone);



    rootrefb.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot snapshot) {
            for(DataSnapshot ds: snapshot.getChildren()){
                if(ds.child("adoemail").getValue().equals(adoemail)){
                    ud_name.setText(ds.child("adoname").getValue(String.class));
                    up_phone.setText(ds.child("adophone").getValue(String.class));
                }
            }
        }

this errors come and my app closed

2020-12-15 09:06:58.949 17074-17074/com.example.adopt_pet_app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.adopt_pet_app, PID: 17074
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.adopt_pet_app/com.example.adopt_pet_app.Adopter_Profile}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3041)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3277)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1969)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7127)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
    at com.example.adopt_pet_app.Adopter_Profile.<init>(Adopter_Profile.java:34)
    at java.lang.Class.newInstance(Native Method)
    at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69)
    at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1219)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3029)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3277) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1969) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:214) 
    at android.app.ActivityThread.main(ActivityThread.java:7127) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975) 

i hope to find answer for it :") or at least tell me how i can understand what this errors mean ??? because its really difficult to understand them thank you

ima
  • 31
  • 3
  • 1
    you have already TAG field `public static final String TAG = "TAG";` and this is exactly what error says ... more over IDE offer you to navigate to this field (to eventually, delete it) – Selvin Dec 15 '20 at 16:54
  • yeah lol i noticed now i wanted to delete the post already but well you answered thx for help btw – ima Dec 15 '20 at 16:58
  • just delete it :D – Selvin Dec 15 '20 at 17:00
  • @Selvin unforcedly im facing new problem with the same code while running the code so i just edit the post :") – ima Dec 15 '20 at 17:11

0 Answers0