我正在尝试首先使用 ViewPager 概念,现在我得到了NoClassDefFoundError
:
06-06 10:50:47.293: E/AndroidRuntime(1295): FATAL EXCEPTION: main
06-06 10:50:47.293: E/AndroidRuntime(1295): java.lang.NoClassDefFoundError: com.example.unserekinder.Bilderbuch
06-06 10:50:47.293: E/AndroidRuntime(1295): at com.example.unserekinder.Ereignisse.onOptionsItemSelected(Ereignisse.java:176)
06-06 10:50:47.293: E/AndroidRuntime(1295): at android.app.Activity.onMenuItemSelected(Activity.java:2548)
06-06 10:50:47.293: E/AndroidRuntime(1295): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
06-06 10:50:47.293: E/AndroidRuntime(1295): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
06-06 10:50:47.293: E/AndroidRuntime(1295): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
06-06 10:50:47.293: E/AndroidRuntime(1295): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
06-06 10:50:47.293: E/AndroidRuntime(1295): at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:156)
06-06 10:50:47.293: E/AndroidRuntime(1295): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
06-06 10:50:47.293: E/AndroidRuntime(1295): at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
06-06 10:50:47.293: E/AndroidRuntime(1295): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
06-06 10:50:47.293: E/AndroidRuntime(1295): at android.widget.AbsListView$1.run(AbsListView.java:3423)
06-06 10:50:47.293: E/AndroidRuntime(1295): at android.os.Handler.handleCallback(Handler.java:725)
06-06 10:50:47.293: E/AndroidRuntime(1295): at android.os.Handler.dispatchMessage(Handler.java:92)
06-06 10:50:47.293: E/AndroidRuntime(1295): at android.os.Looper.loop(Looper.java:137)
06-06 10:50:47.293: E/AndroidRuntime(1295): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-06 10:50:47.293: E/AndroidRuntime(1295): at java.lang.reflect.Method.invokeNative(Native Method)
06-06 10:50:47.293: E/AndroidRuntime(1295): at java.lang.reflect.Method.invoke(Method.java:511)
06-06 10:50:47.293: E/AndroidRuntime(1295): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-06 10:50:47.293: E/AndroidRuntime(1295): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-06 10:50:47.293: E/AndroidRuntime(1295): at dalvik.system.NativeStart.main(Native Method)
这是我的代码:
public class Bilderbuch extends FragmentActivity {
MyPageAdapter pageAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bilderbuch);
List<Fragment> fragments = getFragments();
pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments);
ViewPager pager = (ViewPager)findViewById(R.id.viewpager);
pager.setAdapter(pageAdapter);
}
private List<Fragment> getFragments(){
List<Fragment> fList = new ArrayList<Fragment>();
fList.add(MyFragment.newInstance("Fragment 1"));
fList.add(MyFragment.newInstance("Fragment 2"));
fList.add(MyFragment.newInstance("Fragment 3"));
return fList;
}
private class MyPageAdapter extends FragmentPagerAdapter {
private List<Fragment> fragments;
public MyPageAdapter(FragmentManager fm, List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
@Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}
@Override
public int getCount() {
return this.fragments.size();
}
}
}
public class MyFragment extends Fragment {
public static final String EXTRA_MESSAGE = "EXTRA_MESSAGE";
public static final MyFragment newInstance(String message){
MyFragment f = new MyFragment();
Bundle bdl = new Bundle(1);
bdl.putString(EXTRA_MESSAGE, message);
f.setArguments(bdl);
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String message = getArguments().getString(EXTRA_MESSAGE);
View v = inflater.inflate(R.layout.activity_my_fragment, container, false);
TextView messageTextView = (TextView)v.findViewById(R.id.tvTest);
messageTextView.setText(message);
return v;
}
这是布局文件Bilderbuch
:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
这里是MyFragment
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MyFragment" >
<TextView
android:id="@+id/tvTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
有人能告诉我我的错误在哪里吗?