如何更改或添加更多代碼以使此應用程序停止崩潰?這個活動被稱爲「WhatBin」,我只是想讓一個按鈕聽取人何時點擊並改變文本視圖。 (點擊查看大圖下面有詳細介紹)。Android Studio - 應用程序崩潰
package com.example.tiffany.whatbin;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.w3c.dom.Text;
public class WhatBin extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_what_bin);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final TextView txt_answer = (TextView) findViewById(R.id.txt_answer);
Button btn_go = (Button) findViewById(R.id.btn_go);
btn_go.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txt_answer.setText("Marker - Recycle Bin");
}
});
};
}
下面是XML文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_padddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_what_bin" tools:context=".WhatBin">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go"
android:id="@+id/btn.go"
android:layout_marginBottom="113dp"
android:textColor="@drawable/abc_dialog_material_background_dark"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textEdit"
android:layout_alignBottom="@+id/btn.go"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/btn.go"
android:layout_toStartOf="@+id/btn.go" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/instructiontext"
android:id="@+id/textinstruc"
android:layout_below="@+id/textEdit"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/btn.go"
android:layout_toStartOf="@+id/btn.go" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/txt.1"
android:id="@+id/txt.answer"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
它在您的佈局文件中看起來像一個問題。你能發佈你的XML佈局文件嗎? – hackjutsu
請將錯誤日誌作爲文本發佈,以便我們可以讀取錯誤並找出問題所在。這也允許其他人搜索那個特定的錯誤並找到你的問題。 – NoChinDeluxe
我已經發布了XML文件:) –