Question: I shoul use setText() but how should I use it instead of System.out.println()?
I want to print the result in a TextView. The code is a json reader. sorry I need to write some text to let me post my question.

```
public class JsonReader extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

private static String readAll(Reader rd) throws IOException {
    StringBuilder sb = new StringBuilder();
    int cp;
    while ((cp = rd.read()) != -1) {
        sb.append((char) cp);
    }
    return sb.toString();
}

public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
    InputStream is = new URL(url).openStream();
    try {
        BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
        String jsonText = readAll(rd);
        JSONObject json = new JSONObject(jsonText);
        return json;
    } finally {
        is.close();
    }
}

public static void main(String[] args) throws IOException, JSONException {
    JSONObject json = readJsonFromUrl("http://www.w3schools.com/json/myTutorials.txt");
    System.out.println(json.toString());
    System.out.println(json.get("display"));
    //TextView tv = (TextView) findViewById( R.id.tv );
    //tv.setText(json.toString());
    //tv.setText(json.get("display"));

}

```

}

Answer: 
You need to use **Logs** to print and debug stuff in android.

Generally there are **five methods**, 

```
Log.v() Log.d() Log.i() Log.w() and Log.e()

```

> 
> v for Verbose
> 
> 
> d for Debug
> 
> 
> i for Info
> 
> 
> w for Warnings
> 
> 
> e for Error
> 
> 
> 

**In your case**

```
Log.d("Key", json.toString() + "");
Log.d("Key", json.get("display") + "");

```

And you look for the values in the log cat, using the "Key"
You can use a [`CharArrayWriter`](http://developer.android.com/reference/java/io/CharArrayWriter.html) to collect the output:

```
CharArrayWriter writer = new CharArrayWriter();
// write your stuff
TextView view = ...
view.setText(writer.toString());

```

You'll have to use the methods available to a `Writer` rather than those of a `PrintStream` such as `System.out` (no `println()` methods).

If you want to use basically the same calls to generate the output, you can create a `ByteArrayOutputStream` and wrap it in a `PrintStream`. After writing (and closing the `PrintStream`), retrieve the byte array from the `ByteArrayOutputStream` and convert it to a `String` using one of the `String` constructors. You just have to specify the character encoding you want to use, both when creating the `PrintStream` and when converting the bytes to a `String`.

Another alternative would be to replace printing with simply appending your data to a `StringBuilder`.

A final alternative is simply to append directly to the `TextView`, but that requires converting every piece of output to some sort of `CharSequence`.