美好的一天,我对Android很陌生。当我运行我的应用程序时,我感到很惊讶。这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:rowCount="4"
tools:context="com.example.andani.myapplications2.MainActivity">
<TextView
android:id="@+id/txtName"
android:layout_width="122dp"
android:layout_height="35dp"
android:text="TextView"
android:layout_row="0"
android:layout_column="1"
tools:layout_editor_absoluteX="234dp"
tools:layout_editor_absoluteY="34dp" />
<EditText
android:id="@+id/LblName"
android:layout_width="175dp"
android:layout_height="37dp"
android:layout_row="0"
android:layout_column="0"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="34dp" />
<EditText
android:id="@+id/LblSurname"
android:layout_width="177dp"
android:layout_height="38dp"
android:ems="10"
android:layout_row="1"
android:layout_column="0"
android:inputType="textPersonName"
android:text="Surname"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="100dp" />
<TextView
android:id="@+id/txtSurname"
android:layout_width="123dp"
android:layout_height="37dp"
android:text="TextView"
android:layout_row="1"
android:layout_column="1"
tools:layout_editor_absoluteX="234dp"
tools:layout_editor_absoluteY="100dp" />
<EditText
android:id="@+id/LblInstitute"
android:layout_width="175dp"
android:layout_height="39dp"
android:ems="10"
android:layout_row="2"
android:layout_column="0"
android:inputType="textPersonName"
android:text="Institute"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="159dp" />
<TextView
android:id="@+id/txtInstitute"
android:layout_width="119dp"
android:layout_height="35dp"
android:text="TextView"
android:layout_row="2"
android:layout_column="1"
tools:layout_editor_absoluteX="233dp"
tools:layout_editor_absoluteY="157dp" />
<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="OnClickSubmit"
android:text="Submit"
android:layout_row="3"
android:layout_column="1"
tools:layout_editor_absoluteX="234dp"
tools:layout_editor_absoluteY="231dp" />
<Button
android:id="@+id/btnReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:layout_row="3"
android:layout_column="0"
tools:layout_editor_absoluteX="130dp"
tools:layout_editor_absoluteY="231dp" />
</GridLayout>
在设计屏幕上,布局显示我想要的方式。但是,当我运行应用程序时,我只是得到一个空白屏幕。我怎么可能做错了?这是我的主要活动页面:
package com.example.andani.myapplications2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.*;
import android.view.*;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void OnClickSubmit(View view)
{
TextView LblName=(TextView) findViewById(R.id.txtName);
LblName.getText();
TextView LblSurname=(TextView) findViewById(R.id.txtSurname);
}
}
我注意到的另一件事是,当我没有连接到互联网时,我的模拟器无法启动。继续给我错误:处理完成退出代码-1073741819(0xC0000005)。有没有办法在脱机时运行模拟器。非常感谢。非常感谢您的帮助。
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.andani.myapplications2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我检查了事件日志,我现在认为问题与模拟器有关:
18/04/03
5:49 AM Gradle sync started
5:49 AM Project setup started
5:49 AM Gradle sync finished in 17s 396ms (from cached state)
5:52 AM Executing tasks: [clean, :app:assembleDebug]
5:54 AM Gradle build finished in 1m 54s 721ms
5:55 AM * daemon not running; starting now at tcp:5037
5:55 AM * daemon started successfully
5:55 AM Executing tasks: [:app:assembleDebug]
5:56 AM Emulator: emulator: WARNING: UpdateCheck: Failure: Error
5:56 AM Emulator: emulator: WARNING: UpdateCheck: Failure: Error
6:02 AM Emulator: emulator: ERROR: detected a hanging thread 'Qt event loop'. No response for 15002 ms
6:03 AM Emulator: Process finished with exit code -1073741819 (0xC0000005)