Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.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
在android emulator上运行应用程序时出错_Android_Android Emulator - Fatal编程技术网

在android emulator上运行应用程序时出错

在android emulator上运行应用程序时出错,android,android-emulator,Android,Android Emulator,我已经用XML编写了一个应用程序,但仍然没有用java代码编写类。但仿真器可以显示我的应用程序的名称,然后它说,不幸的是,应用程序已经停止。这个问题我该怎么办 这是我的代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:l

我已经用XML编写了一个应用程序,但仍然没有用java代码编写类。但仿真器可以显示我的应用程序的名称,然后它说,不幸的是,应用程序已经停止。这个问题我该怎么办

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Textview
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"/>
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/TextView2"/>
<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/Button"
    />

</LinearLayout> 

您的应用程序中必须至少有一个activity Java类,以便manifest.xml能够识别并运行它。

您必须使用activity来显示此xml:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
正如您所看到的,您的xml被setContentView方法调用

此活动必须在您的AndroidManifest.xml中用

<activity
        android:name="YOURPACKAGE.ACTIVITY_NAME"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

当您创建Android项目时,它通常会创建某种MainActivity类,即使您还没有编写java代码。关于发生了什么,应该有一些日志输出,你能发布吗?@Chad Campbell:java.lang.classLoader.loadClassClassLoader.java.501在android.view.LayoutInflater.onCreateViewLayoutInflater.java:552….Hi@SetarehNaraghi。问得好Ozturk先生你能告诉我你的电子邮件地址吗?一个地址,我可以发送我的代码给你,真的我有问题,我没有人来帮助我。