android - PreferenceFragment java.lang.RuntimeException -
i follow sample provided commonsware in link single header
and when run it gave me force close below logcat ,
any advice appreciated ,
logcat :
fatal exception: main java.lang.runtimeexception: unable start activity componentinfo {com.commonsware.android.pref1header/com.commonsware.android.pref1header. fragmentsdemo}: android.view.inflateexception: binary xml file line #1: error inflating class fragment @ android.app.activitythread.performlaunchactivity(activitythread.java:1651) @ android.app.activitythread.handlelaunchactivity(activitythread.java:1667) @ android.app.activitythread.access$1500(activitythread.java:117) @ android.app.activitythread$h.handlemessage(activitythread.java:935) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:130) @ android.app.activitythread.main(activitythread.java:3687) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:507) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:867) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:625) @ dalvik.system.nativestart.main(native method) caused by: android.view.inflateexception: binary xml file line #1: error inflating class fragment @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:587) @ android.view.layoutinflater.inflate(layoutinflater.java:386) @ android.view.layoutinflater.inflate(layoutinflater.java:320) @ android.view.layoutinflater.inflate(layoutinflater.java:276) @ com.android.internal.policy.impl.phonewindow.setcontentview (phonewindow.java:216) @ android.app.activity.setcontentview(activity.java:1660) @ com.commonsware.android.pref1header.fragmentsdemo.oncreate (fragmentsdemo.java:28) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) @ android.app.activitythread.performlaunchactivity(activitythread.java:1615) ... 11 more caused by: android.support.v4.app.fragment$instantiationexception: unable instantiate fragment com.commonsware.android.pref1header.preferencecontentsfragment: make sure class name exists, public, , has empty constructor public @ android.support.v4.app.fragment.instantiate(fragment.java:401) @ android.support.v4.app.fragment.instantiate(fragment.java:369) @ android.support.v4.app.fragmentactivity.oncreateview(fragmentactivity.java:272) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:563) ... 19 more caused by: java.lang.classnotfoundexception: com.commonsware.android.pref1header.preferencecontentsfragment in loader dalvik.system.pathclassloader[/data/app/com.commonsware.android.pref1header-1.apk] @ dalvik.system.pathclassloader.findclass(pathclassloader.java:240) @ java.lang.classloader.loadclass(classloader.java:551) @ java.lang.classloader.loadclass(classloader.java:511) @ android.support.v4.app.fragment.instantiate(fragment.java:391) ... 22 more
java class follow :
editpreferences:
public class editpreferences extends preferenceactivity { private boolean needresource=false; @suppresswarnings("deprecation") @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if (needresource || build.version.sdk_int < build.version_codes.honeycomb) { addpreferencesfromresource(r.xml.preferences); } } @override public void onbuildheaders(list<header> target) { if (onishidingheaders() || !onismultipane()) { needresource=true; } else { loadheadersfromresource(r.xml.preference_headers, target); } } }
stockpreferencefragment:
public class stockpreferencefragment extends preferencefragment { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); int res= getactivity().getresources().getidentifier(getarguments().getstring ("resource"), "xml",getactivity().getpackagename()); addpreferencesfromresource(res); } }
preferencecontentsfragment:
public class preferencecontentsfragment extends fragment { private textview checkbox=null; private textview ringtone=null; private textview checkbox2=null; private textview text=null; private textview list=null; @override public view oncreateview(layoutinflater inflater, viewgroup parent, bundle savedinstancestate) { view result=inflater.inflate(r.layout.content, parent, false); checkbox=(textview)result.findviewbyid(r.id.checkbox); ringtone=(textview)result.findviewbyid(r.id.ringtone); checkbox2=(textview)result.findviewbyid(r.id.checkbox2); text=(textview)result.findviewbyid(r.id.text); list=(textview)result.findviewbyid(r.id.list); return(result); } @override public void onresume() { super.onresume(); sharedpreferences prefs= preferencemanager.getdefaultsharedpreferences(getactivity()); checkbox.settext(new boolean(prefs.getboolean("checkbox", false)).tostring()); ringtone.settext(prefs.getstring("ringtone", "<unset>")); checkbox2.settext(new boolean(prefs.getboolean("checkbox2", false)).tostring()); text.settext(prefs.getstring("text", "<unset>")); list.settext(prefs.getstring("list", "<unset>")); } }
fragmentsdemo:
public class fragmentsdemo extends fragmentactivity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); } @override public boolean oncreateoptionsmenu(menu menu) { new menuinflater(this).inflate(r.menu.actions, menu); return(super.oncreateoptionsmenu(menu)); } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case r.id.settings: startactivity(new intent(this, editpreferences.class)); return(true); } return(super.onoptionsitemselected(item)); } }
you better served letting eclipse run past point of exception , @ logcat.
that being said, problem is:
caused by: java.lang.classnotfoundexception: com.commonsware.android.pref1header.preferencecontentsfragment
if moved app own package, need adjust other files match, notably res/xml/preference_headers.xml
.
Comments
Post a Comment