Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – YouTube API : org.json.JSONException: No value for

Posted on November 14, 2022

Solution 1 :

From your LogCat

   org.json.JSONException: No value for videoId

Seems like the JSON object doesn’t contain any value/mapping for the parameter "videoId".

To check if the JSON contains a certain key, use has().

Or, you can use optString() to get an empty string if the mapping doesn’t exist.

Problem :

Error while running my project

 E/ChannelActivity:  New Video IdjxaQXUCdIt0
         New Video IdSz6U9KWa8s8
    W/System.err: org.json.JSONException: No value for videoId
            at org.json.JSONObject.get(JSONObject.java:389)
    W/System.err:     at org.json.JSONObject.getString(JSONObject.java:550)
            at android.com.demo.ChannelActivity$1.onResponse(ChannelActivity.java:73)
            at android.com.demo.ChannelActivity$1.onResponse(ChannelActivity.java:56)
            at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
            at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
            at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
            at android.os.Handler.handleCallback(Handler.java:754)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:165)
            at android.app.ActivityThread.main(ActivityThread.java:6375)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)

Here is my JSONObject Code

JSONObject jsonObject = new JSONObject(response);
                    JSONArray jsonArray=jsonObject.getJSONArray("items");
                    for(int i=0;i<jsonArray.length();i++) {
                        JSONObject jsonObject1 = jsonArray.getJSONObject(i);
                        JSONObject jsonVideoId=jsonObject1.getJSONObject("id");
                        JSONObject jsonsnippet= jsonObject1.getJSONObject("snippet");
                        JSONObject jsonObjectdefault = jsonsnippet.getJSONObject("thumbnails").getJSONObject("medium");
                        String videoid=jsonVideoId.getString("videoId");



                        VideoDetails videoDetails=new VideoDetails();
                        videoDetails.setVideoid(videoid);
                        videoDetails.setTitle(jsonsnippet.getString("title"));
                        videoDetails.setDescribtion(jsonsnippet.getString("description"));
                        videoDetails.setUrl(jsonObjectdefault.getString("url"));

                        videoDetailsArrayList.add(videoDetails);

In order to do that I have Generated API key and pasted into my project.
Steps for generating API Key

Signup to google developer account using google mail

Click on create a project from dropdown icon arrow (YouTube API) at top of the page and type the project name like My YouTube Video App then click on Create button.

Go to API Manager from side menu and choose Registering your application under YouTube APIs and then click Enable API, then you will see a notice which saying Go to Credentials. Then, click that button.

The new page will appear like add credentials to your project and choose YouTube Data API v3 from which API are you using and choose Android as where will you be calling the API from. Finally choose Public data from dada accessing part and then click the button called What credentials do I need?

READ  [ANSWERED] android - How to combine 2 Flows as to pass their values as arguments into suspend fun (which returns String)?
Powered by Inline Related Posts

Then copy pasted my API key to my project.

Comments

Comment posted by Jacintha Rego

May i Know,How can we get the value for videoId??

Comment posted by Swayam

Can you update the question by sharing the JSON object? Also confirm if the object actually contains a param called videoId.

Comment posted by Jacintha Rego

Yes ..I Updated by sharing JSON object

Comment posted by Jacintha Rego

I tried checking with JSON contains videoId using has() and printed in Log..It is showing false

Comment posted by Swayam

You can convert the entire JSONObject into string and print it in log to check what the actual content of JSON is. If

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress