我一直试图运行这个项目,或者从ViewPagerIndicator Library开始。 我不确定在复制上述项目中的代码时我错过了什么。在此先感谢。^^
SampleTabsWithIcons
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import com.viewpagerindicator.IconPagerAdapter;
import com.viewpagerindicator.TabPageIndicator;
public class SampleTabsWithIcons extends FragmentActivity {
private static final String[] CONTENT = new String[] { "Calendar", "Camera", "Alarms", "Location" };
private static final int[] ICONS = new int[] {
R.drawable.perm_group_calendar,
R.drawable.perm_group_camera,
R.drawable.perm_group_device_alarms,
R.drawable.perm_group_location,
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_tabs_with_icons);
FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager());
ViewPager pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(adapter);
TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator);
indicator.setViewPager(pager);
}
class GoogleMusicAdapter extends FragmentPagerAdapter implements IconPagerAdapter {
public GoogleMusicAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
}
@Override
public CharSequence getPageTitle(int position) {
return CONTENT[position % CONTENT.length].toUpperCase();
}
@Override public int getIconResId(int index) {
return ICONS[index];
}
@Override
public int getCount() {
return CONTENT.length;
}
}
}
activity_sample_tabs_with_icons.xml
<?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">
<com.viewpagerindicator.TabPageIndicator
android:id="@+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
logcat的:
07-12 09:56:22.045: E/AndroidRuntime(15435): FATAL EXCEPTION: main
07-12 09:56:22.045: E/AndroidRuntime(15435): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.tabwithicon/com.example.tabwithicon.SampleTabsWithIcons}: java.lang.ClassNotFoundException: com.example.tabwithicon.SampleTabsWithIcons
07-12 09:56:22.045: E/AndroidRuntime(15435): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
07-12 09:56:22.045: E/AndroidRuntime(15435): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
07-12 09:56:22.045: E/AndroidRuntime(15435): at android.app.ActivityThread.access$600(ActivityThread.java:130)
07-12 09:56:22.045: E/AndroidRuntime(15435): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
07-12 09:56:22.045: E/AndroidRuntime(15435): at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 09:56:22.045: E/AndroidRuntime(15435): at android.os.Looper.loop(Looper.java:137)
07-12 09:56:22.045: E/AndroidRuntime(15435): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-12 09:56:22.045: E/AndroidRuntime(15435): at java.lang.reflect.Method.invokeNative(Native Method)
07-12 09:56:22.045: E/AndroidRuntime(15435): at java.lang.reflect.Method.invoke(Method.java:511)
07-12 09:56:22.045: E/AndroidRuntime(15435): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-12 09:56:22.045: E/AndroidRuntime(15435): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-12 09:56:22.045: E/AndroidRuntime(15435): at dalvik.system.NativeStart.main(Native Method)
07-12 09:56:22.045: E/AndroidRuntime(15435): Caused by: java.lang.ClassNotFoundException: com.example.tabwithicon.SampleTabsWithIcons
07-12 09:56:22.045: E/AndroidRuntime(15435): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-12 09:56:22.045: E/AndroidRuntime(15435): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-12 09:56:22.045: E/AndroidRuntime(15435): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-12 09:56:22.045: E/AndroidRuntime(15435): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
07-12 09:56:22.045: E/AndroidRuntime(15435): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
07-12 09:56:22.045: E/AndroidRuntime(15435): ... 11 more
以下是结构:
logcat的:
07-12 10:32:27.415: W/dalvikvm(15756): Unable to resolve superclass of Lcom/example/tabwithicon/SampleTabsWithIcons; (18)
07-12 10:32:27.418: W/dalvikvm(15756): Link of class 'Lcom/example/tabwithicon/SampleTabsWithIcons;' failed
07-12 10:32:27.419: D/AndroidRuntime(15756): Shutting down VM
07-12 10:32:27.422: W/dalvikvm(15756): threadid=1: thread exiting with uncaught exception (group=0x41989300)
答案 0 :(得分:1)
logcat中的错误是ClassNotFoundException
。看行......
Caused by: java.lang.ClassNotFoundException: com.example.tabwithicon.SampleTabsWithIcons
你有这个类,所以应该是package declaration
。检查您是否在应用程序中定义了正确的包。
您的包被定义为com.example.tabwithicon
。检查包装是否正确。