1

I try to open the preference screen with the option menu. The drawable of the option menu is visible in the right corner but when I click on it the app crashes.

Could anyone tell me why?

public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    if (id == R.id.item1) {

        Intent i = new Intent(this, SettingsActivity.class);
        startActivity(i);
        Log.d("onOptionsItemSelected","yes");

        return true;

    }
    Log.d("onOptionsItemSelected","no");

    return super.onOptionsItemSelected(item);
}

public class SettingsActivity extends AppCompatActivity {


@SuppressLint("ResourceType")
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.xml.preferences);
}
public void showDatePicker(View v) {
    DialogFragment newFragment = new DatePickerFragment();
    newFragment.show(getFragmentManager(), "date picker");
}


}

public class DatePickerFragment extends DialogFragment {

public Dialog onCreateDialog(Bundle savedInstanceState) {
    setHasOptionsMenu(true);

    final Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);

    return new DatePickerDialog(getActivity(), dateSetListener, year, month, day);
}

private DatePickerDialog.OnDateSetListener dateSetListener =
        new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, int month, int day) {
                Toast.makeText(getActivity(), "selected date is " + view.getYear() +
                        " / " + (view.getMonth() + 1) +
                        " / " + view.getDayOfMonth(), Toast.LENGTH_SHORT).show();
            }
        };


}

```

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.m.myfirstapp, PID: 4649 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.m.myfirstapp.SettingsActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class PreferenceScreen at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class PreferenceScreen Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class PreferenceScreen Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.PreferenceScreen" on path: DexPathList[[zip file "/data/app/com.example.myfirstapp-1/base.apk", zip file "/data/app/com.example.m.myfirstapp-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.m.myfirstapp-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.m.myfirstapp-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.m.myfirstapp-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.m.myfirstapp-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.m.myfirstapp-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.m.myfirstapp-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.m.myfirstapp-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.m.myfirstapp-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.m.myfirstapp-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.m.myfirstapp-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.m.myfirstapp-1/lib/x86, /system/lib, /vendor/lib]]

ahs123
  • 11
  • 3

0 Answers0