<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" > </android.support.v4.view.ViewPager> </LinearLayout> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- Dummy content. --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="16dp"> <TextView android:id="@android:id/text1" style="?android:textAppearanceLarge" android:textStyle="bold" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" /> <TextView style="?android:textAppearanceMedium" android:lineSpacingMultiplier="1.2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="lorem_ipsum" /> </LinearLayout> </ScrollView> package com.example.viewpager; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.Fragment; import android.support.v4.app.NavUtils; import android.support.v4.view.ViewPager; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends FragmentActivity { private ViewPager viewPager; private ScreenSlidePagerAdapter viewPagerAdapter; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_screen_slide); viewPager = (ViewPager)findViewById(R.id.viewpager); //getSupportFragmentManager replace getFragmentManager FragmentManager mFragments = getSupportFragmentManager(); viewPagerAdapter = new ScreenSlidePagerAdapter(mFragments); viewPager.setAdapter(viewPagerAdapter); viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){ @Override public void onPageSelected(int position) { } }); } @Override public boolean onCreateOptionsMenu(Menu menu){ return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item){ return super.onOptionsItemSelected(item); } private class ScreenSlidePagerAdapter extends android.support.v4.app.FragmentStatePagerAdapter { private static final int NUM_PAGES = 5; public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { return ScreenSlidePageFragment.create(position); } @Override public int getCount() { return NUM_PAGES; } } } package com.example.viewpager; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class ScreenSlidePageFragment extends Fragment { public static final String ARG_PAGE = "page"; /** * The fragment""s page number, which is set to the argument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static Fragment create(int pageNumber) { ScreenSlidePageFragment fragment = new ScreenSlidePageFragment(); Bundle args = new Bundle(); args.putInt(ARG_PAGE, pageNumber); fragment.setArguments(args); return fragment; } public ScreenSlidePageFragment() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_screen_slide_page, container, false); // Set the title view to show the page number. ((TextView) rootView.findViewById(android.R.id.text1)).setText( getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } } |
|
代码在这里
http://download.csdn.net/download/jingshuaizh/8207711 出错信息 11-29 17:44:53.925: D/jdwp(30233): sendBufferedRequest : len=0x45 11-29 17:44:53.927: W/asset(30233): AssetManager-->addDefaultAssets CIP path not exsit! 11-29 17:44:53.949: D/dalvikvm(30233): open_cached_dex_file : /data/app/com.example.viewpager-1.apk /data/dalvik-cache/data@app@com.example.viewpager-1.apk@classes.dex 11-29 17:44:54.168: D/AndroidRuntime(30233): Shutting down VM 11-29 17:44:54.168: W/dalvikvm(30233): threadid=1: thread exiting with uncaught exception (group=0x40e2b978) 11-29 17:44:54.168: W/dalvikvm(30233): threadid=1: uncaught exception occurred 11-29 17:44:54.169: W/System.err(30233): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.viewpager/com.example.viewpager.MainActivity}: java.lang.NullPointerException 11-29 17:44:54.169: W/System.err(30233): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2372) 11-29 17:44:54.169: W/System.err(30233): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424) 11-29 17:44:54.169: W/System.err(30233): at android.app.ActivityThread.access$600(ActivityThread.java:169) 11-29 17:44:54.170: W/System.err(30233): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1388) 11-29 17:44:54.170: W/System.err(30233): at android.os.Handler.dispatchMessage(Handler.java:107) 11-29 17:44:54.170: W/System.err(30233): at android.os.Looper.loop(Looper.java:194) 11-29 17:44:54.170: W/System.err(30233): at android.app.ActivityThread.main(ActivityThread.java:5433) 11-29 17:44:54.170: W/System.err(30233): at java.lang.reflect.Method.invokeNative(Native Method) 11-29 17:44:54.170: W/System.err(30233): at java.lang.reflect.Method.invoke(Method.java:525) 11-29 17:44:54.171: W/System.err(30233): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:922) 11-29 17:44:54.171: W/System.err(30233): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689) 11-29 17:44:54.171: W/System.err(30233): at dalvik.system.NativeStart.main(Native Method) 11-29 17:44:54.171: W/System.err(30233): Caused by: java.lang.NullPointerException 11-29 17:44:54.172: W/System.err(30233): at com.example.viewpager.MainActivity.onCreate(MainActivity.java:29) 11-29 17:44:54.172: W/System.err(30233): at android.app.Activity.performCreate(Activity.java:5211) 11-29 17:44:54.172: W/System.err(30233): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146) 11-29 17:44:54.172: W/System.err(30233): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336) 11-29 17:44:54.172: W/System.err(30233): ... 11 more 11-29 17:44:54.172: W/dalvikvm(30233): threadid=1: calling UncaughtExceptionHandler 11-29 17:44:54.174: E/AndroidRuntime(30233): FATAL EXCEPTION: main 11-29 17:44:54.174: E/AndroidRuntime(30233): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.viewpager/com.example.viewpager.MainActivity}: java.lang.NullPointerException 11-29 17:44:54.174: E/AndroidRuntime(30233): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2372) 11-29 17:44:54.174: E/AndroidRuntime(30233): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2424) 11-29 17:44:54.174: E/AndroidRuntime(30233): at android.app.ActivityThread.access$600(ActivityThread.java:169) 11-29 17:44:54.174: E/AndroidRuntime(30233): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1388) 11-29 17:44:54.174: E/AndroidRuntime(30233): at android.os.Handler.dispatchMessage(Handler.java:107) 11-29 17:44:54.174: E/AndroidRuntime(30233): at android.os.Looper.loop(Looper.java:194) 11-29 17:44:54.174: E/AndroidRuntime(30233): at android.app.ActivityThread.main(ActivityThread.java:5433) 11-29 17:44:54.174: E/AndroidRuntime(30233): at java.lang.reflect.Method.invokeNative(Native Method) 11-29 17:44:54.174: E/AndroidRuntime(30233): at java.lang.reflect.Method.invoke(Method.java:525) 11-29 17:44:54.174: E/AndroidRuntime(30233): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:922) 11-29 17:44:54.174: E/AndroidRuntime(30233): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689) 11-29 17:44:54.174: E/AndroidRuntime(30233): at dalvik.system.NativeStart.main(Native Method) 11-29 17:44:54.174: E/AndroidRuntime(30233): Caused by: java.lang.NullPointerException 11-29 17:44:54.174: E/AndroidRuntime(30233): at com.example.viewpager.MainActivity.onCreate(MainActivity.java:29) 11-29 17:44:54.174: E/AndroidRuntime(30233): at android.app.Activity.performCreate(Activity.java:5211) 11-29 17:44:54.174: E/AndroidRuntime(30233): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146) 11-29 17:44:54.174: E/AndroidRuntime(30233): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336) 11-29 17:44:54.174: E/AndroidRuntime(30233): ... 11 more |
|
50分 |
感觉你是不是V7和V4用混了,没配置好啊
在gen文件夹里是v7的,但是libs里用的又是v4的jar |
google提供了Android Support Library package 系列的包来保证来高版本sdk开发的向下兼容性,即我们用4.x开发时,在1.6等版本上,可以使用高版本的有些特性,如Fragement,ViewPager等,下面,简单说明下这几个版本间的区别:
Android Support v4: 这个包是为了照顾1.6及更高版本而设计的,这个包是使用最广泛的,eclipse新建工程时,都默认带有了。 Android Support v7: 这个包是为了考虑照顾2.1及以上版本而设计的,但不包含更低,故如果不考虑1.6,我们可以采用再加上这个包,另外注意,v7是要依赖v4这个包的,即,两个得同时被包含。 Android Support v13 :这个包的设计是为了android 3.2及更高版本的,一般我们都不常用,平板开发中能用到。 貌似 没有影响的 这两个 |
|
50分 |
应该是你用了高版本的sdk 创建的时候应该给你默认增加的有v7的包和library 之类的 然后你删除了 library 还将v7的包换成了v4的 然后目前资源文件里边再报错 Theme.AppCompat.Light 等等都是删除的那个Compat里边的资源 建议自己删除掉这些报错的Theme
|
怎么解决啊,遇到了同样的问题。。
|