我試圖添加一個設置片段到我的android-app。 所以,我增加了一個XML文件和本次活動:Android設置片段
public class SettingsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
}
}
它正在從onOptionsItemSelected函數調用中的主要活動:
if (id == R.id.action_settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;
}
所以,現在,當我嘗試打開從菜單中的活動,它強制關閉,我在控制檯中得到這個錯誤:
Force-removing child win Window{4190a9a8 u0 PopupWindow:418fc208} from container Window{418dd448 u0 org.name.app/org.name.app.MainActivity}
Failed looking up window
java.lang.IllegalArgumentException: Requested window [email protected] does not exist
at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7934)
at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7925)
at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1047)
at android.os.BinderProxy.sendDeathNotice(Binder.java:493)
at dalvik.system.NativeStart.run(Native Method)
我用add函數代替了替換功能,但它也不管用。我是否需要找到舊片段並將其替換爲新片段,或者我做錯了什麼? – ovmcit5eoivc4