Question: Ok, I have read a lot of questions here on StackOverflow but i still can't understand so i'm opening a new question.

I made a class which function connects to internet and fetches json as string. It works fine in normal Java Application but i can't get it work in my android project. 

I'm getting next error: android.os.NetworkOnMainThreadException

So to my understanding I have to use AsyncTask but I don't know how to wrap my function into it.

Function looks like this:

```
public static String get(String url){
  //connect and get data to string
  // return string
}

```

Like I said it works fine in normal JavaApplication but not in android project.

Thx for help!

Answer: 
One of the best solution for your needs is BackgroundWorker.
Define an empty DataTable in your class and put Ping codes into BackgroundWorker\_DoWork method. then Add result to DataTable.
When this method completed, BackgroundWorker\_WorkerComplete has fired. You should run DoWork method again for next ping.
```
Ping ping = new Ping();

for(int i = 0; i<= number_of_pings; i++)
{
    PingReply pingReply = ping.Send(address_to_send);

    dataGridView1.Rows.Add(address_to_send, pingReply.Address, pingReply.RoundtripTime, pingReply.Status);
    dataGridView1.PerformLayout();
    Application.DoEvents();
}

```