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

时间:2010-07-06 20:47:20

标签: android

我刚开始进行android开发并尝试HelloAndroid教程。我已经被困了几天了。最初,我第一次尝试它,一切都很完美,然后我继续第二次教程一切都破了。所以我想回到最简单的原始教程并弄清楚发生了什么。

我编辑了三个主要文件: HelloAndroid2.java package com.example.HelloAndroid2;

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"/>

的strings.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 }

所以,它只是停留在起点:意图...... 模拟器显示时间,日期和正在充电的fac。我正在开发Android 2.2。 我尝试从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

所以基本上,模拟器上没有任何事情发生,它应该说HelloAndroid或类似的东西。请帮忙。

<?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 个答案:

答案 0 :(得分:1)

WARNING: Application does not specify an API level requirement!

在manifest.xml文件中定义android:minSdkVersion

   </application>

  <uses-sdk android:minSdkVersion="3" />

</manifest> 

答案 1 :(得分:0)

那么为什么不开始简单,并在指定min时创建一个新的AVD。它的SDK,所以它会在那里。

然后要足够可靠地运行AVD,确保没有Android应用程序正在运行,然后从Eclipse Run!Run Configurations ...!Target!Manual!<Run>!启动一个新的Android虚拟设备![然后单击在窗格的订单项上突出显示AVD]!<OK>.

等待事物加载(等待Eclipse Console反馈中的“ActivityManager:Starting:Intent”行)。然后按皮肤上的<Menu>

如果AVD已在运行并且您想再次运行它,请更改Java代码中的一行,然后运行!运行配置...!Target!Automatic!<Apply><Run>

答案 2 :(得分:-1)

我想你忘了在AndroidManifest.xml中定义访问互联网

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