0

I want to change my project from Activity to FragmentActivity. The first step was to create the 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 is a simple LinearLayout with a TextView

The second Step was to (after my SplashScreen) make the parent class to 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 the menu; this adds items to the action bar if it is 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 my SplashScreen is say know:

Intent myInt = new Intent(this, TestFrag.class);
startActivity(myInt);

But alwas i get these errors:

05-18 23:09:51.543: W/dalvikvm(28644): Unable to 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): Could not find class 'ws.stefma.projectname.TestFrag', referenced from method ws.stefma.projectname.Activity_Login_Registration.onCreate
05-18 23:09:51.543: W/dalvikvm(28644): VFY: unable to 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 at 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 with 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):    at ws.stefma.projectname.Activity_Login_Registration.onCreate(Activity_Login_Registration.java:30)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at android.app.Activity.performCreate(Activity.java:5104)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at android.os.Looper.loop(Looper.java:137)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at android.app.ActivityThread.main(ActivityThread.java:5041)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at java.lang.reflect.Method.invokeNative(Native Method)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at java.lang.reflect.Method.invoke(Method.java:511)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-18 23:09:51.593: E/AndroidRuntime(28644):    at dalvik.system.NativeStart.main(Native Method)

I have no idea why... The confused about that: If I go back from FragmentActivity to Activity all runs fine without errors!!!

Also i have these in my AndroidManifest:

<activity android:name="ws.stefma.projectname.TestFrag" />

Update:

I have import the support-v4 libary. My AndroidManifest was declared to minSdk="14" and targetSdk="17". Because i used the support-v4 I have imported on the Fragment-Class

import android.app.support.v4.Fragment

Now i have changed that to

import android.app.Fragment

and it seems to work...

Also i must change the FragmentActivity to Activity. Because the FragmentActivity is only an Class for the support v4 Package!

Update 2 - Solution found: Here is the solution

4

3 に答える 3

0

support-v4 ライブラリを使用する必要はないと思います。そのライブラリを使用する理由を教えてください。min sdk が 14 であることを確認しました。この場合、sopport-v4 を使用しても意味がありません。

ws.stefma.projectname パッケージをチェックアウトしてください。logcat は ws.stefma.projectname.TestFrag が存在しないと言っているからです。

于 2013-05-19T04:12:02.687 に答える