gpt4 book ai didi

java - Android-带有图标的选项卡,未找到类

转载 作者:行者123 更新时间:2023-12-01 14:20:35 25 4
gpt4 key购买 nike

我一直在尝试运行这个提取的项目或从中提取的项目 ViewPagerIndicator Library 。我不确定从上面的项目复制代码时错过了什么。提前致谢。^^

带有图标的示例选项卡

    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>

enter image description here

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

结构如下: enter image description here

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)

最佳答案

logcat 中的错误是 ClassNotFoundException。请参阅该行...

Caused by: java.lang.ClassNotFoundException: com.example.tabwithicon.SampleTabsWithIcons

您拥有该类,因此它可能应该是包声明。检查您是否在应用程序中定义了正确的包。

您的包定义为com.example.tabwithicon。检查这是否是正确的包。

关于java - Android-带有图标的选项卡,未找到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17606469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com