Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Netbeans Android emulator未运行程序_Java_Android_Android Activity_Netbeans_Emulation - Fatal编程技术网

Java Netbeans Android emulator未运行程序

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

我试图在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;

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>