Couldnt get child value From Firebase












0















I couldn't get the value from Firebase. I had 2 class, MainGarden and Resort class. I do also import google-service json file in my database. The value return is only null.



MainGarden.java



package com.example.xh3al3r.myapplication2;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.AsyncTask;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.util.Log;
import android.net.wifi.WifiManager;
import android.text.format.Formatter;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.firebase.client.Firebase;
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;
import com.google.firebase.iid.FirebaseInstanceId;

import javax.annotation.Nonnull;


public class MainGarden extends AppCompatActivity {
TextView textView;
DatabaseReference refmoisture;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_garden);
final TextView moisturevalue = (TextView) findViewById(R.id.textView15);

refmoisture = FirebaseDatabase.getInstance().getReference("Resort");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot resortSnapsot : dataSnapshot.getChildren()) {
Resort model = resortSnapsot.getValue(Resort.class);
moisturevalue.setText( model.getValues());
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


}



}


Resort.class



package com.example.xh3al3r.myapplication2;

public class Resort {
private String Moisture;

public Resort(){

}


public Resort(String moisture){

Moisture=moisture;
}

public String getValues() {
return Moisture;
}

public void setValues(String valuess) {

Moisture=valuess;
}
}


I had attached the json of my database. I wish to getValue of "Moisture" but I just can't.



database structure










share|improve this question

























  • Please search more question on stack overflow, there are tons of examples that you can help you understand the problem.

    – PradyumanDixit
    Nov 16 '18 at 10:00











  • @PradyumanDixit o

    – Jesscy Tey
    Nov 16 '18 at 10:45
















0















I couldn't get the value from Firebase. I had 2 class, MainGarden and Resort class. I do also import google-service json file in my database. The value return is only null.



MainGarden.java



package com.example.xh3al3r.myapplication2;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.AsyncTask;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.util.Log;
import android.net.wifi.WifiManager;
import android.text.format.Formatter;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.firebase.client.Firebase;
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;
import com.google.firebase.iid.FirebaseInstanceId;

import javax.annotation.Nonnull;


public class MainGarden extends AppCompatActivity {
TextView textView;
DatabaseReference refmoisture;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_garden);
final TextView moisturevalue = (TextView) findViewById(R.id.textView15);

refmoisture = FirebaseDatabase.getInstance().getReference("Resort");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot resortSnapsot : dataSnapshot.getChildren()) {
Resort model = resortSnapsot.getValue(Resort.class);
moisturevalue.setText( model.getValues());
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


}



}


Resort.class



package com.example.xh3al3r.myapplication2;

public class Resort {
private String Moisture;

public Resort(){

}


public Resort(String moisture){

Moisture=moisture;
}

public String getValues() {
return Moisture;
}

public void setValues(String valuess) {

Moisture=valuess;
}
}


I had attached the json of my database. I wish to getValue of "Moisture" but I just can't.



database structure










share|improve this question

























  • Please search more question on stack overflow, there are tons of examples that you can help you understand the problem.

    – PradyumanDixit
    Nov 16 '18 at 10:00











  • @PradyumanDixit o

    – Jesscy Tey
    Nov 16 '18 at 10:45














0












0








0








I couldn't get the value from Firebase. I had 2 class, MainGarden and Resort class. I do also import google-service json file in my database. The value return is only null.



MainGarden.java



package com.example.xh3al3r.myapplication2;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.AsyncTask;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.util.Log;
import android.net.wifi.WifiManager;
import android.text.format.Formatter;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.firebase.client.Firebase;
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;
import com.google.firebase.iid.FirebaseInstanceId;

import javax.annotation.Nonnull;


public class MainGarden extends AppCompatActivity {
TextView textView;
DatabaseReference refmoisture;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_garden);
final TextView moisturevalue = (TextView) findViewById(R.id.textView15);

refmoisture = FirebaseDatabase.getInstance().getReference("Resort");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot resortSnapsot : dataSnapshot.getChildren()) {
Resort model = resortSnapsot.getValue(Resort.class);
moisturevalue.setText( model.getValues());
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


}



}


Resort.class



package com.example.xh3al3r.myapplication2;

public class Resort {
private String Moisture;

public Resort(){

}


public Resort(String moisture){

Moisture=moisture;
}

public String getValues() {
return Moisture;
}

public void setValues(String valuess) {

Moisture=valuess;
}
}


I had attached the json of my database. I wish to getValue of "Moisture" but I just can't.



database structure










share|improve this question
















I couldn't get the value from Firebase. I had 2 class, MainGarden and Resort class. I do also import google-service json file in my database. The value return is only null.



MainGarden.java



package com.example.xh3al3r.myapplication2;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.AsyncTask;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.util.Log;
import android.net.wifi.WifiManager;
import android.text.format.Formatter;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.firebase.client.Firebase;
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;
import com.google.firebase.iid.FirebaseInstanceId;

import javax.annotation.Nonnull;


public class MainGarden extends AppCompatActivity {
TextView textView;
DatabaseReference refmoisture;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_garden);
final TextView moisturevalue = (TextView) findViewById(R.id.textView15);

refmoisture = FirebaseDatabase.getInstance().getReference("Resort");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot resortSnapsot : dataSnapshot.getChildren()) {
Resort model = resortSnapsot.getValue(Resort.class);
moisturevalue.setText( model.getValues());
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


}



}


Resort.class



package com.example.xh3al3r.myapplication2;

public class Resort {
private String Moisture;

public Resort(){

}


public Resort(String moisture){

Moisture=moisture;
}

public String getValues() {
return Moisture;
}

public void setValues(String valuess) {

Moisture=valuess;
}
}


I had attached the json of my database. I wish to getValue of "Moisture" but I just can't.



database structure







android firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 10:19









Grimthorr

4,52942238




4,52942238










asked Nov 16 '18 at 9:53









Jesscy TeyJesscy Tey

34




34













  • Please search more question on stack overflow, there are tons of examples that you can help you understand the problem.

    – PradyumanDixit
    Nov 16 '18 at 10:00











  • @PradyumanDixit o

    – Jesscy Tey
    Nov 16 '18 at 10:45



















  • Please search more question on stack overflow, there are tons of examples that you can help you understand the problem.

    – PradyumanDixit
    Nov 16 '18 at 10:00











  • @PradyumanDixit o

    – Jesscy Tey
    Nov 16 '18 at 10:45

















Please search more question on stack overflow, there are tons of examples that you can help you understand the problem.

– PradyumanDixit
Nov 16 '18 at 10:00





Please search more question on stack overflow, there are tons of examples that you can help you understand the problem.

– PradyumanDixit
Nov 16 '18 at 10:00













@PradyumanDixit o

– Jesscy Tey
Nov 16 '18 at 10:45





@PradyumanDixit o

– Jesscy Tey
Nov 16 '18 at 10:45












2 Answers
2






active

oldest

votes


















0














You can make these changes in your code



  refmoisture = FirebaseDatabase.getInstance().getReference("Resort").child("Moisture");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exist()){

String value = dataSnapshot.child("Value").getValue().toString();
moisturevalue.setText( value);
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


Hope It Works !!!






share|improve this answer


























  • Hello Swati, this code is works but it get entire data from Firebase haha What if i only want to get "Moisture"

    – Jesscy Tey
    Nov 16 '18 at 10:07













  • Use-->> dataSnapshot.child("Value").getValue().toString(); if u want to get child of moisture

    – Swati
    Nov 16 '18 at 10:17











  • I changed to the new code yet return null

    – Jesscy Tey
    Nov 16 '18 at 10:27











  • SRY my mistake.. WORKS PERFECTLY..THANKS ALOT

    – Jesscy Tey
    Nov 16 '18 at 10:33











  • Great !! :) @Jesscy Tey

    – Swati
    Nov 16 '18 at 10:37



















1














Use this code



    refmoisture = FirebaseDatabase.getInstance().getReference().child("Resort").child("Moisture");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

String moisture = dataSnapshot.child("Value").getValue().toString();
moisturevalue.setText( moisture);

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});





share|improve this answer



















  • 1





    THANKS!! This can works also

    – Jesscy Tey
    Nov 16 '18 at 11:16












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335300%2fcouldnt-get-child-value-from-firebase%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can make these changes in your code



  refmoisture = FirebaseDatabase.getInstance().getReference("Resort").child("Moisture");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exist()){

String value = dataSnapshot.child("Value").getValue().toString();
moisturevalue.setText( value);
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


Hope It Works !!!






share|improve this answer


























  • Hello Swati, this code is works but it get entire data from Firebase haha What if i only want to get "Moisture"

    – Jesscy Tey
    Nov 16 '18 at 10:07













  • Use-->> dataSnapshot.child("Value").getValue().toString(); if u want to get child of moisture

    – Swati
    Nov 16 '18 at 10:17











  • I changed to the new code yet return null

    – Jesscy Tey
    Nov 16 '18 at 10:27











  • SRY my mistake.. WORKS PERFECTLY..THANKS ALOT

    – Jesscy Tey
    Nov 16 '18 at 10:33











  • Great !! :) @Jesscy Tey

    – Swati
    Nov 16 '18 at 10:37
















0














You can make these changes in your code



  refmoisture = FirebaseDatabase.getInstance().getReference("Resort").child("Moisture");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exist()){

String value = dataSnapshot.child("Value").getValue().toString();
moisturevalue.setText( value);
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


Hope It Works !!!






share|improve this answer


























  • Hello Swati, this code is works but it get entire data from Firebase haha What if i only want to get "Moisture"

    – Jesscy Tey
    Nov 16 '18 at 10:07













  • Use-->> dataSnapshot.child("Value").getValue().toString(); if u want to get child of moisture

    – Swati
    Nov 16 '18 at 10:17











  • I changed to the new code yet return null

    – Jesscy Tey
    Nov 16 '18 at 10:27











  • SRY my mistake.. WORKS PERFECTLY..THANKS ALOT

    – Jesscy Tey
    Nov 16 '18 at 10:33











  • Great !! :) @Jesscy Tey

    – Swati
    Nov 16 '18 at 10:37














0












0








0







You can make these changes in your code



  refmoisture = FirebaseDatabase.getInstance().getReference("Resort").child("Moisture");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exist()){

String value = dataSnapshot.child("Value").getValue().toString();
moisturevalue.setText( value);
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


Hope It Works !!!






share|improve this answer















You can make these changes in your code



  refmoisture = FirebaseDatabase.getInstance().getReference("Resort").child("Moisture");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exist()){

String value = dataSnapshot.child("Value").getValue().toString();
moisturevalue.setText( value);
}
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


Hope It Works !!!







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 10:34

























answered Nov 16 '18 at 10:02









SwatiSwati

6951318




6951318













  • Hello Swati, this code is works but it get entire data from Firebase haha What if i only want to get "Moisture"

    – Jesscy Tey
    Nov 16 '18 at 10:07













  • Use-->> dataSnapshot.child("Value").getValue().toString(); if u want to get child of moisture

    – Swati
    Nov 16 '18 at 10:17











  • I changed to the new code yet return null

    – Jesscy Tey
    Nov 16 '18 at 10:27











  • SRY my mistake.. WORKS PERFECTLY..THANKS ALOT

    – Jesscy Tey
    Nov 16 '18 at 10:33











  • Great !! :) @Jesscy Tey

    – Swati
    Nov 16 '18 at 10:37



















  • Hello Swati, this code is works but it get entire data from Firebase haha What if i only want to get "Moisture"

    – Jesscy Tey
    Nov 16 '18 at 10:07













  • Use-->> dataSnapshot.child("Value").getValue().toString(); if u want to get child of moisture

    – Swati
    Nov 16 '18 at 10:17











  • I changed to the new code yet return null

    – Jesscy Tey
    Nov 16 '18 at 10:27











  • SRY my mistake.. WORKS PERFECTLY..THANKS ALOT

    – Jesscy Tey
    Nov 16 '18 at 10:33











  • Great !! :) @Jesscy Tey

    – Swati
    Nov 16 '18 at 10:37

















Hello Swati, this code is works but it get entire data from Firebase haha What if i only want to get "Moisture"

– Jesscy Tey
Nov 16 '18 at 10:07







Hello Swati, this code is works but it get entire data from Firebase haha What if i only want to get "Moisture"

– Jesscy Tey
Nov 16 '18 at 10:07















Use-->> dataSnapshot.child("Value").getValue().toString(); if u want to get child of moisture

– Swati
Nov 16 '18 at 10:17





Use-->> dataSnapshot.child("Value").getValue().toString(); if u want to get child of moisture

– Swati
Nov 16 '18 at 10:17













I changed to the new code yet return null

– Jesscy Tey
Nov 16 '18 at 10:27





I changed to the new code yet return null

– Jesscy Tey
Nov 16 '18 at 10:27













SRY my mistake.. WORKS PERFECTLY..THANKS ALOT

– Jesscy Tey
Nov 16 '18 at 10:33





SRY my mistake.. WORKS PERFECTLY..THANKS ALOT

– Jesscy Tey
Nov 16 '18 at 10:33













Great !! :) @Jesscy Tey

– Swati
Nov 16 '18 at 10:37





Great !! :) @Jesscy Tey

– Swati
Nov 16 '18 at 10:37













1














Use this code



    refmoisture = FirebaseDatabase.getInstance().getReference().child("Resort").child("Moisture");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

String moisture = dataSnapshot.child("Value").getValue().toString();
moisturevalue.setText( moisture);

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});





share|improve this answer



















  • 1





    THANKS!! This can works also

    – Jesscy Tey
    Nov 16 '18 at 11:16
















1














Use this code



    refmoisture = FirebaseDatabase.getInstance().getReference().child("Resort").child("Moisture");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

String moisture = dataSnapshot.child("Value").getValue().toString();
moisturevalue.setText( moisture);

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});





share|improve this answer



















  • 1





    THANKS!! This can works also

    – Jesscy Tey
    Nov 16 '18 at 11:16














1












1








1







Use this code



    refmoisture = FirebaseDatabase.getInstance().getReference().child("Resort").child("Moisture");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

String moisture = dataSnapshot.child("Value").getValue().toString();
moisturevalue.setText( moisture);

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});





share|improve this answer













Use this code



    refmoisture = FirebaseDatabase.getInstance().getReference().child("Resort").child("Moisture");
refmoisture.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

String moisture = dataSnapshot.child("Value").getValue().toString();
moisturevalue.setText( moisture);

}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 10:06









Ali AhmedAli Ahmed

1,3891314




1,3891314








  • 1





    THANKS!! This can works also

    – Jesscy Tey
    Nov 16 '18 at 11:16














  • 1





    THANKS!! This can works also

    – Jesscy Tey
    Nov 16 '18 at 11:16








1




1





THANKS!! This can works also

– Jesscy Tey
Nov 16 '18 at 11:16





THANKS!! This can works also

– Jesscy Tey
Nov 16 '18 at 11:16


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335300%2fcouldnt-get-child-value-from-firebase%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine