代码之家  ›  专栏  ›  技术社区  ›  oky_sabeni

helloandroid教程错误:请求时间失败

  •  3
  • oky_sabeni  · 技术社区  · 14 年前

    我编辑了三个主要文件: HelloAndroid2.java文件

    import android.app.Activity;
    import android.os.Bundle;
    
    public class HelloAndroid2 extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }
    }
    

    main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/textview"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:text="@string/hello"/>
    

    字符串.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="hello">Hello World, HelloAndroid2!</string>
        <string name="app_name">HelloAndroid2</string>
    </resources>
    

    When I run it, the console output is:
    [2010-07-06 16:37:16 - HelloAndroid2] ------------------------------
    [2010-07-06 16:37:16 - HelloAndroid2] Android Launch!
    [2010-07-06 16:37:16 - HelloAndroid2] adb is running normally.
    [2010-07-06 16:37:16 - HelloAndroid2] Performing com.example.HelloAndroid2.HelloAndroid2 activity launch
    [2010-07-06 16:37:16 - HelloAndroid2] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'HelloWorld'
    [2010-07-06 16:37:16 - HelloAndroid2] WARNING: Application does not specify an API level requirement!
    [2010-07-06 16:37:16 - HelloAndroid2] Device API version is 8 (Android 2.2)
    [2010-07-06 16:37:16 - HelloAndroid2] Uploading HelloAndroid2.apk onto device 'emulator-5554'
    [2010-07-06 16:37:16 - HelloAndroid2] Installing HelloAndroid2.apk...
    [2010-07-06 16:37:22 - HelloAndroid2] Success!
    [2010-07-06 16:37:22 - HelloAndroid2] Starting activity com.example.HelloAndroid2.HelloAndroid2 on device 
    [2010-07-06 16:37:26 - HelloAndroid2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.HelloAndroid2/.HelloAndroid2 }
    

    所以,它只是停留在一开始:意图。。。 我试图从LogCat中获取一些数据,下面是最后几行:

    07-06 20:37:25.935: INFO/AndroidRuntime(387): NOTE: attach of thread 'Binder Thread #3' failed
    07-06 20:37:27.265: INFO/ActivityManager(65): Displayed activity com.example.HelloAndroid2/.HelloAndroid2: 1461 ms (total 1461 ms)
    07-06 20:37:32.376: DEBUG/dalvikvm(114): GC_EXPLICIT freed 562 objects / 31672 bytes in 95ms
    07-06 20:37:37.386: DEBUG/dalvikvm(197): GC_EXPLICIT freed 82 objects / 7592 bytes in 87ms
    07-06 20:37:42.386: DEBUG/dalvikvm(250): GC_EXPLICIT freed 26 objects / 1120 bytes in 102ms
    07-06 20:38:10.437: DEBUG/SntpClient(65): request time failed: java.net.SocketException: Address family not supported by protocol
    

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.HelloAndroid2"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".HelloAndroid2"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
        </application>
    
    
    </manifest> 
    
    3 回复  |  直到 14 年前
        1
  •  0
  •   user225626    14 年前

    所以为什么不从简单开始,创建一个新的AVD,同时为它指定一个min.SDK,这样它就在那里了。

    <Run> !推出新的Android虚拟设备[然后单击窗格的行项目以突出显示AVD]! <OK>.

    <Menu> 在皮肤上。

    <Apply> ! < .

        2
  •  1
  •   Jorgesys    14 年前
    WARNING: Application does not specify an API level requirement!
    

       </application>
    
      <uses-sdk android:minSdkVersion="3" />
    
    </manifest> 
    
        3
  •  -1
  •   user1339266    12 年前

    我想您忘记了在AndroidManifest.xml中定义internet访问

     <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET"/>