有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么在运行Hello World时显示它?

package com.FlickrView;

import 安卓.app.Activity;
import 安卓.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();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
     }
}

共 (2) 个答案

  1. # 1 楼答案

    因为您的GUI文件中有Hello,World。看看res/layout/main.xmlres/values/strings.xml。当您传入R.layout.main(一个int)时,相应的视图将从main加载。xml,它依赖于字符串。xml

  2. # 2 楼答案

    我很确定,因为您有默认的main。xml布局。在此默认布局中,LinearLayout中有一个TextView。TextViews文本设置为“Hello World,yourApplicationName”

    为了显示任何内容,您必须对GUI进行一些操作

    编辑:系统。出来println会将所有内容重定向到您的Android日志。您可以使用Logcat查看日志