Java Netbeans Android emulator未运行程序
我试图在Netbeans Android IDE的模拟器上运行一个非常简单的Hello World程序。代码编译后,模拟器启动(适用于android 4.0.3),但Hello World应用程序不在手机上。我是错过了一些简单的东西还是出了什么问题?代码如下:Java Netbeans Android emulator未运行程序,java,android,android-activity,netbeans,emulation,Java,Android,Android Activity,Netbeans,Emulation,我试图在Netbeans Android IDE的模拟器上运行一个非常简单的Hello World程序。代码编译后,模拟器启动(适用于android 4.0.3),但Hello World应用程序不在手机上。我是错过了一些简单的东西还是出了什么问题?代码如下: package com.test.helloworld; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; pu
package com.test.helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class helloworld extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView text1 = new TextView(this);
text1.setText(“Hello World”);
setContentView(text1);
}
}
您没有正确获取文本视图。您需要这样做:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView text1 = (TextView) findViewById(R.id.yourcustomid);
text1.setText(“Hello World”);
}
这里的这一行TextView text1=(TextView)findViewById(R.id.yourcustomid)
是如何获取为活动创建的布局的id(应该在main.xml中),它可能如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/yourcustomid"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>