5

Nun, ich habe mich entschieden, einfach mit dem Pagertitlestrip zu gehen. Ich nehme an, dass die Unterstützungsbibliothek, die ich verwende, pagertabstrip nicht enthält. Ich bin mir nicht sicher, wie ich das beheben könnte, weil ich dachte, ich hätte alles korrekt aktualisiert. Edit: Gibt es das einfach nicht mehr? Wenn ich den PagerTabStrip zu einem PagerTitleStrip ändere, funktioniert alles, aber ich kann nicht mit den Titeln interagieren, die erwartet werden, weil ich deshalb PagerTabStrip verwenden wollte.PageTabStrip Klasse nicht gefunden Ausnahme

Ich bin zurück zu den Grundlagen gegangen, um die Wurzel meines Problems zu finden. Ich begann ein neues Projekt importiert ABS. Ich habe einen sehr einfachen PagerAdapter und ein einfaches Fragment eingerichtet. Ich habe ein Beispiel aus einem Commons-Buch verwendet und trotzdem bekomme ich immer noch den gleichen Fehler. Klasse nicht gefunden Ausnahme. Kann PagerTabStrip nicht finden. Stack-Posted erhält jedes Mal den gleichen Fehler. Wenn ich den PagerTabStrip entferne, funktioniert alles richtig.

xml

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/pager" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <android.support.v4.view.PagerTabStrip 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" /> 

</android.support.v4.view.ViewPager> 

MainActivity

package com.example.pagetabswipe; 

import android.os.Bundle; 
import android.support.v4.view.ViewPager; 
import android.view.Menu; 

import com.actionbarsherlock.app.SherlockFragmentActivity; 

public class MainActivity extends SherlockFragmentActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     ViewPager pager = (ViewPager)findViewById(R.id.pager); 
     pager.setAdapter(new SampleAdapter(getSupportFragmentManager(), this)); 
    } 
} 

Adapter

package com.example.pagetabswipe; 

import android.content.Context; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentPagerAdapter; 

public class SampleAdapter extends FragmentPagerAdapter { 
    Context ctxt=null; 
    public SampleAdapter(FragmentManager fm, Context ctxt) { 
     super(fm); 
     this.ctxt=ctxt; 
     // TODO Auto-generated constructor stub 
    } 

    @Override 
    public Fragment getItem(int position) { 
     return (EditorFragment.newInstance(position)); 
    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return 10; 
    } 
    @Override 
    public String getPageTitle(int position) { 
    return(EditorFragment.getTitle(ctxt, position)); 
    } 
} 

Fragment

package com.example.pagetabswipe; 

import android.content.Context; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.EditText; 
import com.actionbarsherlock.app.SherlockFragment; 

public class EditorFragment extends SherlockFragment { 
    private static final String KEY_POSITION = "position"; 

    static EditorFragment newInstance(int position) { 
     EditorFragment frag = new EditorFragment(); 
     Bundle args = new Bundle(); 
     args.putInt(KEY_POSITION, position); 
     frag.setArguments(args); 
     return (frag); 
    } 

    static String getTitle(Context ctxt, int position) { 
     return (String.format(ctxt.getString(R.string.hint), position + 1)); 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     View result = inflater.inflate(R.layout.editor, container, false); 
     EditText editor = (EditText) result.findViewById(R.id.editor); 
     int position = getArguments().getInt(KEY_POSITION, -1); 
     editor.setHint(getTitle(getActivity(), position)); 
     return (result); 
    } 
} 

Fehler

11-24 18:01:25.630: E/AndroidRuntime(3505): FATAL EXCEPTION: main 
11-24 18:01:25.630: E/AndroidRuntime(3505): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pagetabswipe/com.example.pagetabswipe.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class android.support.v4.view.PagerTabStrip 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.app.ActivityThread.access$1500(ActivityThread.java:124) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.os.Handler.dispatchMessage(Handler.java:99) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.os.Looper.loop(Looper.java:130) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.app.ActivityThread.main(ActivityThread.java:3806) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at java.lang.reflect.Method.invokeNative(Native Method) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at java.lang.reflect.Method.invoke(Method.java:507) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at dalvik.system.NativeStart.main(Native Method) 
11-24 18:01:25.630: E/AndroidRuntime(3505): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class android.support.v4.view.PagerTabStrip 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:853) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at com.example.pagetabswipe.MainActivity.onCreate(MainActivity.java:14) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  ... 11 more 
11-24 18:01:25.630: E/AndroidRuntime(3505): Caused by: java.lang.ClassNotFoundException: android.support.v4.view.PagerTabStrip in loader dalvik.system.PathClassLoader[/data/app/com.example.pagetabswipe-2.apk] 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.view.LayoutInflater.createView(LayoutInflater.java:471) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570) 
11-24 18:01:25.630: E/AndroidRuntime(3505):  ... 20 more 

Jede Hilfe wäre genial. Ich bin mir nicht sicher, wo ich nachsehen kann, um dieses Problem zu beheben. Ich habe das Gefühl, dass ich etwas sehr Grundlegendes verpasst habe, das verhindert, dass PagerTabStrip in der Support-Bibliothek gefunden wird.

+0

Haben Sie eine Lösung für dieses Problem gefunden? Ich habe momentan das selbe Problem. –

Antwort

9

Für mich wurde dies aufgrund der zugrunde liegenden actionbarsherlock-Bibliothek mit einer alten Version der Support-Bibliothek.

Von Eclipse, habe ich Android-Support-Bibliothek aus dem Build-Pfad der actionbarsherlock-Bibliothek-Projekt entfernt.

Dann folgte ich dem Rat hier, PagerTabStrip cannot be resolved to a type,

Rechts auf Sie Projekt klicken ..

Klick auf "Android Tools" -> "Add Support Library"

nach, dass es wird die Android-support.jar herunterladen. und füge es deinem Projekt hinzu.

nach, dass Ihre Eclipse erkennt PagerTabStrip

+0

Das klingt korrekt. Ich habe Eclipse schon lange nicht mehr benutzt, aber es würde Sinn machen, dass die Support-Bibliothek in ABS mich daran hindert, die richtige Support-Bibliothek zu benutzen. Ich hatte dieses Problem auch mit anderen Bibliotheken und das war eine gute Lösung. – doubleA