I am really frustrated. I've been trying this for the past week but no success.
http://www.billboard.com/charts/artist-100 I am wanting to parse the names of the artists from here and I have done so with the code, but whenever I run the program, I get the ArrayList size is 0 and it is really frustrating at this point and I thought of just giving up.
This is my whole class. It always prints that the arraylist has no size. What do I do?
http://www.billboard.com/charts/artist-100 I am wanting to parse the names of the artists from here and I have done so with the code, but whenever I run the program, I get the ArrayList size is 0 and it is really frustrating at this point and I thought of just giving up.
Code:
package com.uw.aakarsh.myapplication2;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.graphics.BitmapFactory;
import android.media.Image;
import android.os.AsyncTask;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import org.jsoup.Jsoup;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.util.Log;
import android.graphics.Bitmap;
import android.widget.ImageView;
import android.widget.ListAdapter;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.io.*;
import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutionException;
public class MainActivity extends AppCompatActivity {
ArrayList<String> Names = new ArrayList<String>();
public class getName extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... Void) {
Document doc;
try {
String url = "http://www.billboard.com/charts/artist-100";
doc = Jsoup.connect(url).get();
Elements names = doc.select("div.chart-row__title > h2.chart-row__song");
for (Element p : names)
Names.add(p.text().toString());
}
catch(IOException ex){
}
return null;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new getName().execute();
System.out.println(Names.size());
}
}
This is my whole class. It always prints that the arraylist has no size. What do I do?