当前位置:编程学习 > wap >>

Android4.0 helloworld出不来,求解

刚接触android
系统 XP 
模拟器 android4.0
代码如下:

package com.example.helloworld;

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

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello World, Android, This is Tan");
setContentView(tv);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}


运行后显示

不管怎么鼠标拖动都是这样

然后发现日志报错:

[2013-11-01 09:27:41 - HelloWorld] New emulator found: emulator-5554
[2013-11-01 09:27:41 - HelloWorld] Waiting for HOME ('android.process.acore') to be launched...
[2013-11-01 09:29:02 - HelloWorld] HOME is up on device 'emulator-5554'
[2013-11-01 09:29:02 - HelloWorld] Uploading HelloWorld.apk onto device 'emulator-5554'
[2013-11-01 09:29:02 - HelloWorld] Installing HelloWorld.apk...
[2013-11-01 09:31:21 - HelloWorld] Failed to install HelloWorld.apk on device 'emulator-5554!
[2013-11-01 09:31:21 - HelloWorld] (null)
[2013-11-01 09:31:22 - HelloWorld] Launch canceled!




请教一下这是什么原因?? --------------------编程问答-------------------- 模拟器还没开机,等看到锁屏界面了再把应用装上去。 --------------------编程问答-------------------- 模拟器一般启动时间蛮长的。再等一会儿吧。
另外你的代码也有问题。
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //后面才是具体要执行的动作,顺序不能颠倒。
} --------------------编程问答-------------------- 模拟器似乎要2-3分钟启动,是吗? --------------------编程问答-------------------- 模拟器启动要看你的电脑配置以及分配给开发的内存。
另外你不用布局吗! --------------------编程问答-------------------- 一般大家的模拟器启动大约多少时间? --------------------编程问答--------------------
 TextView tv = new TextView(this);
        tv.setText("Hello World, Android, This is Tan");
        setContentView(tv);

这个不对啊
setContentView(R.layout.activity_main);
TextView tv=(TextView) findViewById(R.id.tv);tv.setText("Hello World, Android, This is Tan");
--------------------编程问答-------------------- 不是非得用setContentView (int layoutResID)来显示一个layout的。setContentView有个重载的方法setContentView (View view),接受一个view作为参数,直接把这个view显示在屏幕上。 --------------------编程问答--------------------
引用 7 楼 tantahe 的回复:
不是非得用setContentView (int layoutResID)来显示一个layout的。setContentView有个重载的方法setContentView (View view),接受一个view作为参数,直接把这个view显示在屏幕上。

引用
super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //后面才是具体要执行的动作,顺序不能颠倒。

7楼是对的啊。 --------------------编程问答-------------------- 强烈建议使用virtualbox+android-x86取代模拟器 --------------------编程问答-------------------- 优点是啥?贴图,
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,