android - Error by starting FragmentActivity -
i want change project activity fragmentactivity. first step create fragment:
public class frag1 extends fragment { public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater .inflate(r.layout.detail_fragment, container, false); return view; } }
the detail_fragment simple linearlayout textview
the second step (after splashscreen) make parent class fragmentactivity:
public class testfrag extends fragmentactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.frag_main); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.activity_main, menu); return true; } }
the r.layout.frag_main:
<fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/frag" android:name=".fragments.frag1" android:layout_width="match_parent" android:layout_height="match_parent" />
on splashscreen know:
intent myint = new intent(this, testfrag.class); startactivity(myint);
but alwas these errors:
05-18 23:09:51.543: w/dalvikvm(28644): unable resolve superclass of lws/stefma/projectname/testfrag; (20) 05-18 23:09:51.543: w/dalvikvm(28644): link of class 'lws/stefma/projectname/testfrag;' failed 05-18 23:09:51.543: e/dalvikvm(28644): not find class 'ws.stefma.projectname.testfrag', referenced method ws.stefma.projectname.activity_login_registration.oncreate 05-18 23:09:51.543: w/dalvikvm(28644): vfy: unable resolve const-class 94 (lws/stefma/projectname/testfrag;) in lws/stefma/projectname/activity_login_registration; 05-18 23:09:51.543: d/dalvikvm(28644): vfy: replacing opcode 0x1c @ 0x000b 05-18 23:09:51.583: d/androidruntime(28644): shutting down vm 05-18 23:09:51.583: w/dalvikvm(28644): threadid=1: thread exiting uncaught exception (group=0x41850930) 05-18 23:09:51.593: e/androidruntime(28644): fatal exception: main 05-18 23:09:51.593: e/androidruntime(28644): java.lang.noclassdeffounderror: ws.stefma.projectname.testfrag 05-18 23:09:51.593: e/androidruntime(28644): @ ws.stefma.projectname.activity_login_registration.oncreate(activity_login_registration.java:30) 05-18 23:09:51.593: e/androidruntime(28644): @ android.app.activity.performcreate(activity.java:5104) 05-18 23:09:51.593: e/androidruntime(28644): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 05-18 23:09:51.593: e/androidruntime(28644): @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 05-18 23:09:51.593: e/androidruntime(28644): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 05-18 23:09:51.593: e/androidruntime(28644): @ android.app.activitythread.access$600(activitythread.java:141) 05-18 23:09:51.593: e/androidruntime(28644): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 05-18 23:09:51.593: e/androidruntime(28644): @ android.os.handler.dispatchmessage(handler.java:99) 05-18 23:09:51.593: e/androidruntime(28644): @ android.os.looper.loop(looper.java:137) 05-18 23:09:51.593: e/androidruntime(28644): @ android.app.activitythread.main(activitythread.java:5041) 05-18 23:09:51.593: e/androidruntime(28644): @ java.lang.reflect.method.invokenative(native method) 05-18 23:09:51.593: e/androidruntime(28644): @ java.lang.reflect.method.invoke(method.java:511) 05-18 23:09:51.593: e/androidruntime(28644): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-18 23:09:51.593: e/androidruntime(28644): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-18 23:09:51.593: e/androidruntime(28644): @ dalvik.system.nativestart.main(native method)
i have no idea why... confused that: if go fragmentactivity
activity
runs fine without errors!!!
also have these in androidmanifest:
<activity android:name="ws.stefma.projectname.testfrag" />
update:
i have import support-v4 libary
. androidmanifest
declared minsdk="14"
, targetsdk="17"
. because used support-v4 have imported on fragment-class
import android.app.support.v4.fragment
now have changed to
import android.app.fragment
and seems work...
also must change fragmentactivity
activity
. because fragmentactivity
class support v4 package!
update 2 - solution found: here solution
change r.layout.frag_main like:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <fragment android:id="@+id/fragment1" android:name="ws.stefma.projectname.frag1" android:layout_width="match_parent" android:layout_height="wrap_content" /> </linearlayout>
Comments
Post a Comment