Я работаю над экраном настроек для приложения, и я даже не получил его, чтобы отображать экран перед его сбоем. Я ознакомился с несколькими учебными материалами об общих предпочтениях, и мой код похож на их, но ничего не сработало. Я думаю, проблема в моем файле preferences.xml, потому что я прокомментировал все, кроме открытия файла XML в моей PreferenceActivity.
Вот мой файл preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Password">
<EditTextPreference
android:name="Your Password"
android:title="Password"
android:defaultValue=""
android:summary="For logging in if facial recognition fails"
android:key="password" />
<EditTextPreference
android:name="Max Attempts"
android:title="Max Attempts"
android:defaultValue="3"
android:summary="Max number of times to try authentication before falling back to password"
android:key="maxAttempts" />
</PreferenceCategory>
<PreferenceCategory
android:title="Security">
<CheckBoxPreference
android:title="Intruder Alert"
android:defaultValue="false"
android:summary="Notify me if you detect a face other than mine"
android:key="intruderAlert" />
</PreferenceCategory>
<PreferenceCategory
android:title="Intruder Notification">
<EditTextPreference
android:name="Your Email"
android:title="email"
android:defaultValue=""
android:summary="An email address for us to notify"
android:key="email" />
<EditTextPreference
android:name="Your Phone Number"
android:title="phoneNumber"
android:defaultValue=""
android:summary="A phone number for us to notify"
android:key="phoneNumber" />
</PreferenceCategory>
</PreferenceScreen>
И, если я ошибаюсь, и моя проблема - это мой java файл, здесь PreferenceActivity. Большинство из них закомментировано на данный момент, но программа по-прежнему падает.
public class Preferences extends PreferenceActivity implements OnSharedPreferenceChangeListener {
/*private EditTextPreference password;
private EditTextPreference maxAttempts;
private CheckBoxPreference intruderAlert;
private EditTextPreference email;
private EditTextPreference phoneNumber;
String PassWord;
int MaxAttempts;
boolean IntruderAlert;
String Email;
String PhoneNumber;*/
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
//password = (EditTextPreference) getPreferenceScreen().findPreference("password");
//maxAttempts = (EditTextPreference) getPreferenceScreen().findPreference("maxAttempts");
//intruderAlert = (CheckBoxPreference) getPreferenceScreen().findPreference("intruderAlert");
//email = (EditTextPreference) getPreferenceScreen().findPreference("email");
//phoneNumber = (EditTextPreference) getPreferenceScreen().findPreference("phoneNumber");
}
private void setSummaries()
{
}
@Override
protected void onResume()
{
/*super.onResume();
String intruderAlertSetting;
if (intruderAlert.isChecked())
intruderAlertSetting = "on";
else
intruderAlertSetting = "off";
password.setSummary("Your password is " +password.getText()+ ".");
maxAttempts.setSummary("The max attempts that will be made is "+maxAttempts.getText() + ".");
intruderAlert.setSummary("You have intruder alert set to" + intruderAlertSetting+".");
if (email.getText().equals(""))
email.setSummary("You have no email address stored.");
else
email.setSummary("Your stored email address is "+email.getText() + ".");
if (phoneNumber.getText().equals(""))
phoneNumber.setSummary("You have no phone number stored.");
else
phoneNumber.setSummary("Your stored phone number is " + phoneNumber.getText()+".");
// Set up a listener whenever a key changes
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);*/
}
@Override
protected void onPause()
{
/*super.onPause();
String intruderAlertSetting;
if (intruderAlert.isChecked())
intruderAlertSetting = "on";
else
intruderAlertSetting = "off";
password.setSummary("Your password is " +password.getText()+ ".");
maxAttempts.setSummary("The max attempts that will be made is "+maxAttempts.getText() + ".");
intruderAlert.setSummary("You have intruder alert set to" + intruderAlertSetting+".");
if (email.getText().equals(""))
email.setSummary("You have no email address stored.");
else
email.setSummary("Your stored email address is "+email.getText() + ".");
if (phoneNumber.getText().equals(""))
phoneNumber.setSummary("You have no phone number stored.");
else
phoneNumber.setSummary("Your stored phone number is " + phoneNumber.getText()+".");
// Unregister the listener whenever a key changes
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);*/
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key)
{
/*String intruderAlertSetting;
if (intruderAlert.isChecked())
intruderAlertSetting = "on";
else
intruderAlertSetting = "off";
password.setSummary("Your password is " +password.getText()+ ".");
maxAttempts.setSummary("The max attempts that will be made is "+maxAttempts.getText() + ".");
intruderAlert.setSummary("You have intruder alert set to" + intruderAlertSetting+".");
if (email.getText().equals(""))
email.setSummary("You have no email address stored.");
else
email.setSummary("Your stored email address is "+email.getText() + ".");
if (phoneNumber.getText().equals(""))
phoneNumber.setSummary("You have no phone number stored.");
else
phoneNumber.setSummary("Your stored phone number is " + phoneNumber.getText()+".");
PassWord = password.getText();
MaxAttempts = Integer.parseInt(maxAttempts.getText());
IntruderAlert = intruderAlert.isChecked();
Email = email.getText();
PhoneNumber = phoneNumber.getText();*/
}
}
Вот информация LogCat о сбое:
04-23 16:37:09.181: WARN/dalvikvm(818): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): FATAL EXCEPTION: main
04-23 16:37:09.221: ERROR/AndroidRuntime(818): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cs.fsu.edu.project4/com.cs.fsu.edu.project4.Preferences}: android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.os.Looper.loop(Looper.java:123)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.app.ActivityThread.main(ActivityThread.java:3647)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at java.lang.reflect.Method.invoke(Method.java:507)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at dalvik.system.NativeStart.main(Native Method)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.app.Activity.setContentView(Activity.java:1657)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at com.cs.fsu.edu.project4.Preferences.onCreate(Preferences.java:33)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): ... 11 more
04-23 16:37:09.221: ERROR/AndroidRuntime(818): Caused by: java.lang.ClassNotFoundException: android.view.PreferenceScreen in loader dalvik.system.PathClassLoader[/data/app/com.cs.fsu.edu.project4-1.apk]
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
04-23 16:37:09.221: ERROR/AndroidRuntime(818): ... 19 more
04-23 16:37:09.251: WARN/ActivityManager(62): Force finishing activity com.cs.fsu.edu.project4/.Preferences