我正在尝试添加一个密码(我没有使用alertDialog)和一个启动画面(这是我的问题)密码在它询问时工作但在此之前我得到了一个崩溃的原因工作
我为启动画面制作了一个XML文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:id="@+id/splashscreen"
android:layout_gravity="center"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:src="@drawable/untitled">
</ImageView></LinearLayout>
当我尝试添加命令以在主程序中获取启动画面时
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Login");
alert.setMessage("Enter Pin :");
alert.setCancelable(false);
setContentView(R.layout.splashscreen);
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
String compar = "123456";
if(value.equals(compar))
{
Log.d( TAG, "Pin Value : " + value);
copiezmView.setVisibility(View.VISIBLE);
}
else
{
Toast.makeText(getApplicationContext(), "Acces Denied", Toast.LENGTH_SHORT).show();
alerta();
}
我得到了这次崩溃
java.lang.RuntimeException: Unable to start activity ComponentInfo{///////}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
那么我做错了什么?启动画面的目的是我想要在AlertDialog后面并且在后面的内容之前,所以用户如果不知道密码无法看到后面的内容(我使用setView,但仅适用于linearLayout)而不是PrefferenceScreen
完整的logCat
04-12 13:09:49.734: E/AndroidRuntime(1731): FATAL EXCEPTION: main
04-12 13:09:49.734: E/AndroidRuntime(1731): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zegoggles.smssync/com.zegoggles.smssync.SmsSync}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.os.Looper.loop(Looper.java:137)
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.app.ActivityThread.main(ActivityThread.java:5039)
04-12 13:09:49.734: E/AndroidRuntime(1731): at java.lang.reflect.Method.invokeNative(Native Method)
04-12 13:09:49.734: E/AndroidRuntime(1731): at java.lang.reflect.Method.invoke(Method.java:511)
04-12 13:09:49.734: E/AndroidRuntime(1731): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-12 13:09:49.734: E/AndroidRuntime(1731): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-12 13:09:49.734: E/AndroidRuntime(1731): at dalvik.system.NativeStart.main(Native Method)
04-12 13:09:49.734: E/AndroidRuntime(1731): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.preference.PreferenceActivity.onContentChanged(PreferenceActivity.java:959)
04-12 13:09:49.734: E/AndroidRuntime(1731): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.app.Activity.setContentView(Activity.java:1881)
04-12 13:09:49.734: E/AndroidRuntime(1731): at com.zegoggles.smssync.SmsSync.alerta(SmsSync.java:132)
04-12 13:09:49.734: E/AndroidRuntime(1731): at com.zegoggles.smssync.SmsSync.onCreate(SmsSync.java:118)
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.app.Activity.performCreate(Activity.java:5104)
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-12 13:09:49.734: E/AndroidRuntime(1731): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-12 13:09:49.734: E/AndroidRuntime(1731): ... 11 more
答案 0 :(得分:2)
从1行崩溃输出我可以看出,你有一个ListActivity
。而您尚未将ListView
ID设为@android:id/list
。
将listview ID设为
android:id="@android:id/list"
你的问题将得到解决。希望它有所帮助。