Saturday, February 22, 2014

Xiongtai help me find a simple demo error java.lang.NoSuchMethodError


I realized according to the official API http://android.toolib.net/guide/topics/ui/settings.html a setting interface, click to enter the setup menu Activity feature not finished, is being given
menuWhich set the interface using the official recommended frangment form:

Activtiy setting interface:

public class settingActivity extends Activity {

@ Override
protected void onCreate (Bundle savedInstanceState) {
/ / TODO Auto-generated method stub
super.onCreate (savedInstanceState);
... getFragmentManager () beginTransaction () replace (android.R.id.content, new settingFragment ()) commit ();
}


}



Fragment settings interface:

public class settingFragment extends PreferenceFragment {

@ Override
public void onCreate (Bundle savedInstanceState) {
/ / TODO Auto-generated method stub
super.onCreate (savedInstanceState);
addPreferencesFromResource (R.xml.setting);
}

}



R.xml.setting:


android: key = "settings"
android: title = "Settings">
android: key = "basic"
android: title = "Basic Settings">
android: key = "text"
android: title = "text"
/>
android: key = "lightMode"
android: title = "night mode"
android: summaryOn = "Enabled"
android: summaryOff = "not enabled" />
android: key = "textSize"
android: title = "Text Size"
android: dialogTitle = "text size"
android: entries = "@ array / textSize_entry"
android: entryValues ​​= "@ array / textSize_entry_value"
android: defaultValue = "0" />

android: key = "clean"
android: title = "Clear History">
android: key = "cleanHistory"
android: title = "Clear History" />





Error:

11-08 15:58:59.570: E / AndroidRuntime (4108): FATAL EXCEPTION: main
11-08 15:58:59.570: E / AndroidRuntime (4108): java.lang.NoSuchMethodError: com.example.android_preference.settingActivity.getFragmentManager
11-08 15:58:59.570: E / AndroidRuntime (4108): at com.example.android_preference.settingActivity.onCreate (settingActivity.java: 15)
11-08 15:58:59.570: E / AndroidRuntime (4108): at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java: 1047)
11-08 15:58:59.570: E / AndroidRuntime (4108): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 1612)
11-08 15:58:59.570: E / AndroidRuntime (4108): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java: 1664)
11-08 15:58:59.570: E / AndroidRuntime (4108): at android.app.ActivityThread.access $ 1500 (ActivityThread.java: 118)
11-08 15:58:59.570: E / AndroidRuntime (4108): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java: 932)
11-08 15:58:59.570: E / AndroidRuntime (4108): at android.os.Handler.dispatchMessage (Handler.java: 99)
11-08 15:58:59.570: E / AndroidRuntime (4108): at android.os.Looper.loop (Looper.java: 130)
11-08 15:58:59.570: E / AndroidRuntime (4108): at android.app.ActivityThread.main (ActivityThread.java: 3690)
11-08 15:58:59.570: E / AndroidRuntime (4108): at java.lang.reflect.Method.invokeNative (Native Method)
11-08 15:58:59.570: E / AndroidRuntime (4108): at java.lang.reflect.Method.invoke (Method.java: 507)
11-08 15:58:59.570: E / AndroidRuntime (4108): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 853)
11-08 15:58:59.570: E / AndroidRuntime (4108): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 611)
11-08 15:58:59.570: E / AndroidRuntime (4108): at dalvik.system.NativeStart.main (Native Method)
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
getFragmentManager need to API 11, your test machine using what system?
Reply:
cited a floor youngc527 reply:
getFragmentManager needs API 11, your test machine using what system?


Well, you said it right! ! Replaced by a virtual machine, no error has been resolved!
In eoe forum to ask, say what you want to answer the question a group of inherited fragmentActivity hey
Reply:
getFragmentManager () This method is only 3.0 in the future, and look at your development sdk version right, Manifest in setting the minimum version is not greater than 11.
If you want to look at the version 3.0 is compatible to devolve android-support-v4.jar this jar in the libs directory () instead of using getSupportFragmentManager getFragmentManager ().

No comments:

Post a Comment