嘿,我是编程新手,我需要一些帮助,我正在为学校做一个项目,它是一个 android 应用程序,用户在其中输入单词到文本字段,然后这些单词用于创建故事,比如 mad libs . 当我在手机上调试时,我似乎看不到我的代码有什么问题,它只显示一个白屏。有人可以向我指出我做错了什么吗?谢谢...
MainActivity.java:
package com.joe.madlibs;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
EditText Noun, Adj, Name, Verb, Verb2, Noun2, Adj2;
Button Submit;
TextView Story;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Noun = (EditText) findViewById(R.id.noun1);
Adj = (EditText) findViewById(R.id.adjective1);
Name = (EditText) findViewById(R.id.name1);
Verb = (EditText) findViewById(R.id.verb1);
Verb2 = (EditText) findViewById(R.id.verb2);
Noun2 = (EditText) findViewById(R.id.noun2);
Adj2 = (EditText) findViewById(R.id.adj2);
String noun = Noun.getText().toString();
String adj = Adj.getText().toString();
String name = Name.getText().toString();
String verb = Verb.getText().toString();
String verb2 = Verb2.getText().toString();
String noun2 = Noun2.getText().toString();
String adj2 = Adj2.getText().toString();
Submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<EditText
android:id="@+id/noun1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/linearLayout1"
android:layout_alignTop="@+id/linearLayout1"
android:ems="10"
android:hint="@string/noun" >
</EditText>
<EditText
android:id="@+id/verb1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/name1"
android:layout_alignBottom="@+id/name1"
android:layout_alignRight="@+id/storyBox"
android:ems="10"
android:hint="@string/verb" />
<EditText
android:id="@+id/adjective1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/noun1"
android:layout_alignBottom="@+id/noun1"
android:layout_alignLeft="@+id/verb1"
android:ems="10"
android:hint="@string/adjective" />
<EditText
android:id="@+id/name1"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/noun1"
android:layout_below="@+id/noun1"
android:ems="10"
android:hint="@string/name" />
<EditText
android:id="@+id/verb2"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/name1"
android:layout_below="@+id/name1"
android:ems="10"
android:hint="@string/verb" />
<EditText
android:id="@+id/adj2"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/verb1"
android:layout_below="@+id/verb1"
android:ems="10"
android:hint="Adjective" />
<EditText
android:id="@+id/noun2"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/verb2"
android:layout_below="@+id/verb2"
android:ems="10"
android:hint="Noun" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Click here to get your story!" />
<TextView
android:id="@+id/storyBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/noun2"
android:layout_below="@+id/button1"
android:layout_marginTop="18dp"
android:text="This is where your story will go!"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Joe.madlibs"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.Joe.madlibs.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>