开发者

Why is this displaying Hello World when I run it?

开发者 https://www.devze.com 2023-01-15 19:16 出处:网络
package com.FlickrView; import android.app.Activity; import android.os.Bundle; import java.net.*; import java.io.*;
package com.FlickrView;

import android.app.Activity;
import android.os.Bundle;
import java.net.*;
import java.io.*;

public class FlickrView extends Activity {

     /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        try {
            URL flickr = new URL("http://api.flickr.com/services/feeds/photos_public.gne?id=39350419@N06&lang=en-us&format=rss_200");
            URLConnection flickrConnect = flickr.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(flickrConnect.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) 
                System.out.println(inputLine);
            in.close();
        } 
        catch (MalformedURLException e) {
          System.out.println("Unable to load URL");
          e.printStackTrace();
      开发者_C百科  } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
     }
}


Because you have Hello, World in your GUI files. Look at res/layout/main.xml and res/values/strings.xml. When you pass in R.layout.main (an int), the corresponding view is loaded from main.xml, which depends on strings.xml.


I'm quite sure because you have the default main.xml layout. In this default layout there is a TextView in a LinearLayout . The TextViews text is set to "Hello World, yourApplicationName".

You have to do something with your GUI in order to get anything displayed.

EDIT: System.out.println will redirect everything to your Android log. You can view the log using Logcat.

0

精彩评论

暂无评论...
验证码 换一张
取 消