J
JustinTime
Fortgeschrittenes Mitglied
- 19
Hallo zusammen,
ich versuche gerade ein vorhandenes Android Programm von einer normalen TabActivity auf eine aktuellere mit Fragments umzuschreiben. Bisher hatte ich mit Fragmenten nie Schwierigkeiten aber dieses mal stehe ich vor einer für mich nicht zu erklärenden Problematik.
Zum test habe ich erstmal sämtliche Logik aus meiner Main Klasse entfernt dann sieht sie noch so aus.
Das main_layout welches ich erstmal nur kopiert habe sieht so aus
Wenn ich versuche das ganze in diesem sehr übersichtlichen Zustand zum laufen zu bringen spuckt er mir nur diese Fehler aus
Der Fehler liegt also eindeutig am TabHost aber ich habe nicht die geringste Ahnung was ich noch verändern sollte. Ich habe FragmentActivity erweitert damit die SupportLibary genutzt wird und der 2. Import verweißt auch auf diese Libary. Ich habe auch versucht tabHost explizit mit
zu deklarieren ohne Erfolg. Das Project von von Eclipse cleanen zu lassen brachte auch keinen Erfolg denn ich dachte das eventuell irgendwie mit den verweisen in R nicht ganz stimmt. Hat irgendwer weitere Ideen wo das Problem liegen könnte?
ich versuche gerade ein vorhandenes Android Programm von einer normalen TabActivity auf eine aktuellere mit Fragments umzuschreiben. Bisher hatte ich mit Fragmenten nie Schwierigkeiten aber dieses mal stehe ich vor einer für mich nicht zu erklärenden Problematik.
Zum test habe ich erstmal sämtliche Logik aus meiner Main Klasse entfernt dann sieht sie noch so aus.
Code:
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
public class MainActivity extends FragmentActivity {
FragmentTabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
tabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
}
}
Das main_layout welches ich erstmal nur kopiert habe sieht so aus
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</TabHost>
</LinearLayout>
Wenn ich versuche das ganze in diesem sehr übersichtlichen Zustand zum laufen zu bringen spuckt er mir nur diese Fehler aus
Code:
06-10 03:44:58.929: E/AndroidRuntime(5933): FATAL EXCEPTION: main
06-10 03:44:58.929: E/AndroidRuntime(5933): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hsmerseburg/com.example.hsmerseburg.MainActivity}: java.lang.ClassCastException: [B]android.widget.TabHost cannot be cast to android.support.v4.app.FragmentTabHost[/B]
06-10 03:44:58.929: E/AndroidRuntime(5933): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
06-10 03:44:58.929: E/AndroidRuntime(5933): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
06-10 03:44:58.929: E/AndroidRuntime(5933): at android.app.ActivityThread.access$600(ActivityThread.java:130)
06-10 03:44:58.929: E/AndroidRuntime(5933): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
06-10 03:44:58.929: E/AndroidRuntime(5933): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 03:44:58.929: E/AndroidRuntime(5933): at android.os.Looper.loop(Looper.java:137)
06-10 03:44:58.929: E/AndroidRuntime(5933): at android.app.ActivityThread.main(ActivityThread.java:4745)
06-10 03:44:58.929: E/AndroidRuntime(5933): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 03:44:58.929: E/AndroidRuntime(5933): at java.lang.reflect.Method.invoke(Method.java:511)
06-10 03:44:58.929: E/AndroidRuntime(5933): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-10 03:44:58.929: E/AndroidRuntime(5933): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-10 03:44:58.929: E/AndroidRuntime(5933): at dalvik.system.NativeStart.main(Native Method)
06-10 03:44:58.929: E/AndroidRuntime(5933): Caused by: java.lang.ClassCastException: [B]android.widget.TabHost cannot be cast to android.support.v4.app.FragmentTabHost[/B]
06-10 03:44:58.929: E/AndroidRuntime(5933): at com.example.hsmerseburg.MainActivity.onCreate(MainActivity.java:14)
06-10 03:44:58.929: E/AndroidRuntime(5933): at android.app.Activity.performCreate(Activity.java:5008)
06-10 03:44:58.929: E/AndroidRuntime(5933): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
06-10 03:44:58.929: E/AndroidRuntime(5933): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
06-10 03:44:58.929: E/AndroidRuntime(5933): ... 11 more
Der Fehler liegt also eindeutig am TabHost aber ich habe nicht die geringste Ahnung was ich noch verändern sollte. Ich habe FragmentActivity erweitert damit die SupportLibary genutzt wird und der 2. Import verweißt auch auf diese Libary. Ich habe auch versucht tabHost explizit mit
Code:
private android.support.v4.app.FragmentTabHost tabHost;