简体   繁体   English

eclipse上的android不会运行世界

[英]android on eclipse wont run hello world

I am trying to set up an eclipse environment on windows 64. I think I have done everything in the tutorial (developer.android.com) but when I select the project in eclipse to run i get the emulator to pop up but it doesn't show hello world. 我试图在Windows 64上设置一个eclipse环境。我想我已经完成了教程(developer.android.com)中的所有操作,但是当我选择要运行的eclipse项目时,我会弹出仿真器,但它没有向世界问好。

I tried android version 2.1 and the emulator poped up and just eventual went to a black screen after showing ANDROID... 我尝试了Android 2.1版,然后弹出了模拟器并最终在显示ANDROID后进入黑屏...

I tried as 4.0.3 and after the emulator popped up I just saw a plane jane android phone interface it wouldn't run my app. 我尝试使用4.0.3,并在模拟器弹出后,我仅看到一个平面jane android手机界面,它将无法运行我的应用程序。 The code is below. 代码如下。 Does anyone know what i am missing? 有人知道我在想什么吗?

Eclipse displays the following when I run the emulator 当我运行模拟器时,Eclipse显示以下内容

[2012-02-19 11:58:40 - trst] ------------------------------
[2012-02-19 11:58:40 - trst] Android Launch!
[2012-02-19 11:58:40 - trst] adb is running normally.
[2012-02-19 11:58:40 - trst] Performing com.example.helloandroid.TrstActivity activity launch
[2012-02-19 11:58:40 - trst] Automatic Target Mode: launching new emulator with compatible AVD 'interface'
[2012-02-19 11:58:40 - trst] Launching a new emulator with Virtual Device 'interface'
[2012-02-19 11:58:55 - Emulator] emulator: WARNING: Unable to create sensors port: Unknown error
[2012-02-19 11:58:55 - trst] New emulator found: emulator-5554
[2012-02-19 11:58:55 - trst] Waiting for HOME ('android.process.acore') to be launched...

code: 码:

package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class TrstActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        tv.setText("Hello, Android");
        setContentView(tv);
    }
}

I just would like to add that I saw the Android screen and it did nothing for at least 2 minutes and I thought my application had crashed also. 我只是想补充一点,我看到了Android屏幕,并且至少有2分钟没有执行任何操作,而且我认为我的应用程序也崩溃了。 But actually I think this was just the virtual device booting up. 但是实际上我认为这只是虚拟设备启动。

After two or three minutes, the Android log was replaced by a login/splash screen - once I clicked on unlock ... I finally saw my "hello world" message .... what relief !!!! 两三分钟后,Android日志被登录/启动屏幕替换-一旦我单击了解锁...我终于看到了我的“ hello world”消息...。

I restarted Eclipse,opened the main activity.java file in src folder,changed the string to hello android and ran the code. 我重新启动Eclipse,打开src文件夹中的main activity.java文件,将字符串更改为hello android,然后运行了代码。 It pops out an error saying: no such file/string found. 它弹出一个错误,说: no such file/string found. Then I renamed it back to hello_world and ran and it worked. 然后,我将其重命名为hello_world并运行,它起作用了。

Apparent solution may be just try clicking on back button of emulator. 明显的解决方案可能只是尝试单击模拟器的后退按钮。 (as I couldn't find any other mistake in your code) (因为我在您的代码中找不到其他错误)
Also please paste Logcat so that we can identify exact cause. 另外,请粘贴Logcat,以便我们找出确切原因。

Does console give you anything in the logs about why it doesn't run? 控制台是否在日志中为您提供任何有关为何无法运行的信息? I've never used setContentView(int) like that. 我从来没有那样使用过setContentView(int)。 I've always used it with a layout like R.layout.hello (or whatever you have here) and then you can reference the TextView like this 我一直将其与R.layout.hello之类的布局(或此处使用的任何布局)一起使用,然后可以像这样引用TextView

TextView mTextView = findViewById(R.id.myTextView);
mTextView.setText("Hello, Android!");

Hope this helps. 希望这可以帮助。

您可能遇到与初次启动时相同的问题,仿真器需要相当长的时间才能启动,请等待5至10分钟,如果仍然失败,则需要向我们展示logcat。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM