Android Question I need urgent help with CustomListView update and JsonParser error

eSolution

Member
Licensed User
Longtime User
Hi, I have an app that use a customlistview (the class) to display the content of several youtube playlists. I use multiple requests to the yt api to get the content of the youtube playlists in batches of 50 videos then display the results in the custom list. I have a back button that will close the customlistview activity and return to the main menu (activity) then I can get the next 50 videos and send them to the customlistview and so on... The problem is that every time I call the clv activity the new videos are added to the old ones in the customlistview, the list is not starting clean, it has the videos from the last request in it... I have no idea how to fix this

The second problem is that the response from youtube is in json format and I'm using JsonParser . When I "click" on a menu item that request videos from a new playlist (different from the one already displayed when first using the app) I get a java error:

java.lang.RuntimeException: Object should first be initialized (Map).

(this error is given when I press the first menu item - videos 1 to 50 - the start of the first playlist or when I press the 5th menu item - videos 200 to 251)

Why I get this error since sometimes, for some requests (the requests are in the same format and will have a similar response from yt server) , it will display the results with no error???

How do I fix those errors?? I need urgent help with this :D

I have attached the project, please play a little with it, you will be able to reproduce the errors.

I use the latest b4a: 3.82 and this libs: CustomRSSView 1.2; HTTP 1.36; HttpUtils 2.01; JSON 1.1; Reflection 2.4; StringUtils 1.02
 

Attachments

  • projectListTest.zip
    15.8 KB · Views: 239

eSolution

Member
Licensed User
Longtime User
yes I did :) Is not the solution that I need. I need a more structured way of displaying the results as part of my app and I don't want to use the native youtube app, I display and play the yt videos in my app ... I don't want to get users to use another app, I want the users to spend time on my app and see my ads :))

I think the way I made it is the best solution, I just need some help to fix the errors...
 
Last edited:
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
I've not got access to my laptop at the moment but you can use clv.clear to reset your customlistview. Replace clv with the name of your customlistview.
With regard to the other fault, are you sure your not trying to add an item to the list that doesn't exist yet? Maybe try and log the results before adding to the list view.

Regards,
RandomCoder
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
If you are using the CustomRSSView you could do this (you add your variables of course):
B4X:
...

rssView.ParseRSS("http://gdata.youtube.com/feeds/base/users/basic4android/uploads?start-index=1&max-results=50&alt=rss&orderby=published&v=2")
Just an idea.
 
Upvote 0

eSolution

Member
Licensed User
Longtime User
If you are using the CustomRSSView you could do this (you add your variables of course):
B4X:
...

rssView.ParseRSS("http://gdata.youtube.com/feeds/base/users/basic4android/uploads?start-index=1&max-results=50&alt=rss&orderby=published&v=2")
Just an idea.
I already use this to in another part of my app for a different reason :) (to display a yt search result)...

What I really need now is to solve the Json parser problem first and the customlistview after that :)


I've not got access to my laptop at the moment but you can use clv.clear to reset your customlistview. Replace clv with the name of your customlistview.
With regard to the other fault, are you sure your not trying to add an item to the list that doesn't exist yet? Maybe try and log the results before adding to the list view.

Regards,
RandomCoder

I already tried this and is not working ...
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
it doesn't return a thumbnail value that's why you get the error in the second described issue.

you might solve your issues like this...

B4X:
LVLlinks.Clear

For Each colitems As Map In items
    Dim media_url As String
    Dim video As Map = colitems.Get("video")
       
        If(video.ContainsKey("thumbnail")) Then
            Dim thumbnail As Map = video.Get("thumbnail")
            Dim sqDefault As String = thumbnail.Get("sqDefault")
            media_url = sqDefault
        End If       
       
        Dim title As String = video.Get("title")
        Dim id As String = video.Get("id")
       
    Dim linkComp As String = media_url & ";" & title & ";" & id
   
    LVLlinks.Add(linkComp)
Next
 
Upvote 0

eSolution

Member
Licensed User
Longtime User
I have solved the CustomListView problem, I needed to clear a list where I stored the values used to populate the listview each time the activity is started.

I still need to solve the problem that crushes my app: the json parser java error...
 
Upvote 0

eSolution

Member
Licensed User
Longtime User
it doesn't return a thumbnail value that's why you get the error in the second described issue.

you might solve your issues like this...

B4X:
LVLlinks.Clear

For Each colitems As Map In items
    Dim media_url As String
    Dim video As Map = colitems.Get("video")
     
        If(video.ContainsKey("thumbnail")) Then
            Dim thumbnail As Map = video.Get("thumbnail")
            Dim sqDefault As String = thumbnail.Get("sqDefault")
            media_url = sqDefault
        End If     
     
        Dim title As String = video.Get("title")
        Dim id As String = video.Get("id")
     
    Dim linkComp As String = media_url & ";" & title & ";" & id
 
    LVLlinks.Add(linkComp)
Next
Now I have seen your post, I have already used LVLlinks.clear to solve the first isue. I will try now the code you suggested! Thank you!

EDIT: Nope, this did not solved the Java error when clicking a "menu item" that will get videos from another playlist (videos 200-251 and above)
 
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
see my post above, I don't get any error but the progress window doesn't go away either :)
(I have really low wifi strenght here which might be a problem on the video lookup)
 
Upvote 0

eSolution

Member
Licensed User
Longtime User
see my post above, I don't get any error but the progress window doesn't go away either :)
(I have really low wifi strenght here which might be a problem on the video lookup)


I have tried your solution, the java error is not from the tumbnail missing ...all videos have tumbnails, if you wait a little, depending on your internet speed you will see all the tumbnail being populated...

The problem is: I have videos from 2 playlists, when I click on the menu item that will call the videos from the second playlist (is the exact same http request to yt api just the playlist code changed) I get this error in the parser. I know that the request is ok, I get the json response from it!
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
weird, I got the error the first time I tried and it didn't have thumbnail key in the returned map.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
ok, I installed a router here with wireless access point just for the wifi part.

everything runs fast now and I think I see what the problem is.

like I said I had these missing thumbnail info the first time.

When go through the first list I see this aswell. there are 2 items marked as "Private video" and there is no thumbnail there.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
can you explain where that is?

when I click a video in the list it just gives me the parameters behind that listview item.
 
Upvote 0

eSolution

Member
Licensed User
Longtime User
can you explain where that is?

when I click a video in the list it just gives me the parameters behind that listview item.
no, not in the customlistview! In the main activity you have a list/menu that will open the customlistview activity. Depending on what item you click in the main activity the customlistview activity will launch and display a list of videos from a yt playlist. All is fine with the first 4 menu items in the main activity, those menu items request videos from one playlist in batches of 50 videos (first 50 then the next from 51 to 100 then the next 50 and so on). From the fifth menu item I have changed the playlist, I use the same http request to the yt server but I have changed the ID of the yt playlist so now the customlistview activity should display the first 50 videos from the new playlist and then the next 50 and so on... But when I click the fifth menu item in the main activity I get the java error in the parser (or if you click any other menu item that retrieve videos from another playlist). I know that the request is ok and that I get the Json response but the parser is now giving me that java error ... I have no idea what is going on :)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
I went through most of them and didn't get any errors (with my mods active)
 
Upvote 0

eSolution

Member
Licensed User
Longtime User
I went through most of them and didn't get any errors (with my mods active)
Very strange... if I modify the example that I posted it works fine with your modifications but if I implement them in my app (the posted code is a part of my app) I got the error ... and the only thing that is changed is the playlist codes ... :)

EDIT: I put my real playlists in the example and it is not working, I got the same error... May be I have other missing parts in the Json answer ... I'll take a deeper look in to the json response since it is obvious that the missing thumbnail solution fixed the example code ...
 
Last edited:
Upvote 0

eSolution

Member
Licensed User
Longtime User
Problem solved! When requesting the videos from the new playlist the startIndex parameter has to start from 1 again or the Json response will not contain video data, just minimum info about the playlist :D
Damn :D is good to have a community to have a brainstorming session with :D
 
Upvote 0
Top