Так что я знаю, что это связано с моей линией кода «startActivity (myIntent)». Вот мой первый файл с информацией о деятельностиПочему мое приложение для Android рушится?
public class Commander2 extends Activity {
/** Called when the activity is first created. */
private static final String TAG = "AccessCodeEntry";
private static final String LEVEL_ONE_ACCESS_CODE = "derp";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.accesscodeentry);
}
protected void onDestroy() {
super.onDestroy();
}
public void accessCodeEntered(View v) {
EditText loginPassword = (EditText) findViewById(R.id.editText1);
if(loginPassword.toString().equals(LEVEL_ONE_ACCESS_CODE)) {
Intent myIntent = new Intent(Commander2.this, LevelOne.class);
startActivity(myIntent);
} else {
Intent myIntent = new Intent(Commander2.this, LevelZero.class);
startActivity(myIntent);
}
}
}
Вот и файл XML.
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="accessCodeEntered"
android:text="OK" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="19dp"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/editText1"
android:layout_alignLeft="@+id/editText1"
android:text="Enter Access Code, or leave blank for Level 0"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Мой код как раз выходит, как только я ввожу пароль и нажимаю кнопку OK, независимо от того, какой результат. Я прокомментировал строки startActivity (myIntent), и код заканчивается без сбоев. Кто-нибудь знает, что я делаю неправильно?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.eti"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:name=".Commander2"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LevelOne"
android:label="@string/app_name">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LevelZero"
android:label="@string/app_name">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Добавили ли вы активность LevelOne в свой манифест? – Ryan