1
此特定錯誤消息在SO和Web上很受歡迎,但我仍無法從任何建議的解決方案中找到適用於我的解決方案。在添加內容錯誤之前,必須先調用requestFeature(),然後在片段中實現DatePicker
我試圖添加一個DatePicker到我的片段,當點擊一個按鈕時被觸發。但是這個錯誤不斷彈出。這是我正在使用的片段類:
public class MyFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
Context context;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
//Use the current date as the default value for the picker
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
//Create a new instance of datepicker and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.my_layout, container, false);
Button reminderButton = (Button) rootView.findViewById(R.id.dueDateButton);
reminderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment dialogFragment = new MyFragment();
dialogFragment.show(getFragmentManager(), "datePicker");
}
});
context = getActivity();
return rootView;
}
}
此片段處理選項卡式活動中的其中一個視圖。我曾嘗試加入:
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
之前:
View rootView = inflater.inflate(R.layout.newdebt_layout, container, false);
沒有運氣。 我自己也嘗試添加此:
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
權在這個片段被嵌入沒有運氣也該活動的setContentView()
方法之前。
我看過this,this和this問題和其他一些沒有運氣的人。
在堆棧跟蹤中,代碼中沒有特定的行被標記。
05-27 06:17:30.687 23204-23204/com.ojonugwaochalifu.blablabla E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.ojonugwaochalifu.blablabla, PID: 23204
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:336)
at com.android.internal.app.AlertController.installContent(AlertController.java:242)
at android.app.AlertDialog.onCreate(AlertDialog.java:337)
at android.app.Dialog.dispatchOnCreate(Dialog.java:374)
at android.app.Dialog.show(Dialog.java:267)
at android.support.v4.app.DialogFragment.onStart(DialogFragment.java:399)
at android.support.v4.app.Fragment.performStart(Fragment.java:1813)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:989)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
at dalvik.system.NativeStart.main(Native Method)
請發佈整個堆棧跟蹤,注意跟蹤中的哪些行引用上面的代碼片段中的行。 – CommonsWare
@CommonsWare我剛剛添加了這個。正如你所看到的,沒有特定的代碼行被確定爲問題的根源。 –