Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
分析Firebase实时数据库Android中的数据时从获取null_Android_Firebase_Firebase Realtime Database - Fatal编程技术网

分析Firebase实时数据库Android中的数据时从获取null

分析Firebase实时数据库Android中的数据时从获取null,android,firebase,firebase-realtime-database,Android,Firebase,Firebase Realtime Database,我正在集成firebase实时数据库,firebase新闻和分类中有两个列表 当我尝试从categoryId=1获取新闻时,它可以正常工作,但当我选择categoryId=2时,我在数组响应中得到了两个空值 [ null, null, { image="https://zdnet3.cbsistatic.com/hub/i/2016/06/29/a6f69a53-88f3-4e1b-9b59-2287c81e7671/bdc6cc9e6d26866aa44

我正在集成firebase实时数据库,firebase新闻和分类中有两个列表

当我尝试从categoryId=1获取新闻时,它可以正常工作,但当我选择categoryId=2时,我在数组响应中得到了两个空值

[
    null,
    null,
    {
        image="https://zdnet3.cbsistatic.com/hub/i/2016/06/29/a6f69a53-88f3-4e1b-9b59-2287c81e7671/bdc6cc9e6d26866aa44607d87e43f082/syme-ios-v-android.jpg",
        description="PrabhudasLilladheranalystAniketPandesaidinanote.Weremaincautiousonoveralldemandenvironmentandas",
        news_url="https://www.google.co.in",
        short_desc="AndroidisbetterthaniOS",
        title="Technology",
        categoryId="2"
    },
    {
        image="https://i.gadgets360cdn.com/large/oneplus_7T_pro_event_1570722059050.jpg?output-quality=80&output-format=webp",
        description="OnePlusLaunchEventstartedwiththecompany'sco-founderCarlPeionthestage.HebeganbytalkingaboutOxygenOS.PeicitedastudythatclaimsthatOxygenOSisoneofthetopthreereasonswhyOnePlususerslovethecompany.HealsotalkedaboutOxygenOSbetaprocessandhowithelpsthecompanygathersignificantamountoffeedbackabouttheoperatingsystembeforerollingoutanewversionwidely",
        news_url="https://gadgets.ndtv.com/mobiles/news/oneplus-7t-pro-launch-live-updates-mclaren-edition-london-price-specifications-2114715",
        short_desc="OnePlus7TProMcLarenEditionIsOfficial:LiveUpdates",
        title="Technology",
        categoryId="2"
    }
]
这是我从询问中得到的回答

 mChildReference = databaseReference.child("news_data").orderByChild("categoryId").equalTo(categoryId);

      mChildReference.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              Toast.makeText(context,dataSnapshot.toString(),Toast.LENGTH_SHORT).show();

              String json =  dataSnapshot.getValue().toString();
              try {
                  JSONArray obj = new JSONArray(json);

              } catch (Throwable t) {
                  Log.e("Catch", "Could not parse malformed JSON: \"" + json + "\"");
              }
          }
          @Override
          public void onCancelled(@NonNull DatabaseError databaseError) {

          }
      });
错误:
org.json.JSONObject$1类型的值null无法在
onDataChange
内转换为JSONObject,请检查如下:

    for(DataSnapshot ds : dataSnapshot.getChildren()) { 
        if(ds != null) {
            //Do stuff here
        }
    }

请提供您的数据库Structure@Md.Asaduzzaman请检查我编辑的问题尝试我的答案并让我知道顺便说一下,我看不到类别ID 2data@Md.AsaduzzamancategoryId 2和categoryId 1结构相同。说明为什么我要检查null,如果null不能理解你想说什么,则跳过