我不明白錯誤在哪裏,因爲它似乎不是源於我的應用程序的問題,而似乎是在它自己的支持庫中。viewpager.draw上的Android java null
我剛剛意識到,這個錯誤只發生在Android 2.1更新1和有時android 2.2 froyo的舊設備上。在我的設備android 2.3和沒有問題。我不能用任何設備重現這個問題,或者甚至用配置了相同規格的手機來解決這個問題
我看了這整天沒有找到問題。
java.lang.NullPointerException
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1366)
at android.view.View.draw(View.java:6743)
at android.support.v4.view.ViewPager.draw(SourceFile:1923)
at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
at android.view.View.draw(View.java:6743)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
at android.view.View.draw(View.java:6743)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1843)
at android.view.ViewRoot.draw(ViewRoot.java:1407)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
at dalvik.system.NativeStart.main(Native Method)
而且從主要活動的onCreate
代碼中的線性佈局尋呼機只是一組點在用戶是什麼視圖尋呼機號碼來指示。該填入尋呼機的是把點屏幕下方由ViewPager getCount將retrived viewpagers數())
的PageListener只是檢查時viewpager作爲切換頁面和繪製相應的點用另一種顏色
pager = (LinearLayout) findViewById(R.id.pager); appViewPager = (ViewPager) findViewById(R.id.AppViewPager); adapter = new MyPagerAdapter(this, appsList); appViewPager.setAdapter(adapter); populatePager(); PageListener pageListener = new PageListener(); appViewPager.setOnPageChangeListener(pageListener);
而且MyPagerAdapter代碼:
public class MyPagerAdapter extends PagerAdapter implements OnCancelListener {
private Context ctx = null;
public ArrayList<App> appsList;
public MyPagerAdapter(Context ctx, ArrayList<App> appsList) {
this.ctx = ctx;
this.appsList = appsList;
}
@Override
public int getCount() {
int listsize = appsList.size();
int numOfAppsPerPage = Integer.valueOf(ctx.getResources().getString(R.string.grid_number_of_apps_per_page));
float num = Float.valueOf(listsize)/Float.valueOf(numOfAppsPerPage);
float rest = num % 1;
int numOfPagers = Math.round(num - rest);
if (rest > 0 || numOfPagers == 0) {
numOfPagers = numOfPagers + 1;
}
return numOfPagers;
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.grid, null);
GridView gridview = (GridView) view.findViewById(R.id.gridview);
int starterPosition;
int numOfAppsPerPage = Integer.valueOf(ctx.getResources().getString(R.string.grid_number_of_apps_per_page));
starterPosition = numOfAppsPerPage * position;
int enderPosition = starterPosition + numOfAppsPerPage;
// Log.e("ViewPagerPosition", "Position:" + position);
int appsListSize = appsList.size();
if (enderPosition > appsListSize) {
enderPosition = appsListSize;
}
ArrayList<App> shorterList = new ArrayList<App>(appsList.subList(
starterPosition, enderPosition));
final AppLauncherAdapter grid = new AppLauncherAdapter(ctx, shorterList);
gridview.setAdapter(grid);
((ViewPager) collection).addView(gridview, 0);
return gridview;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public Parcelable saveState() {
return null;
}
}
任何想法?
您的應用程序運行的操作系統...... –
讓我們來看看你使用完成:)現在,您可以查看代碼ViewPager – LuxuryMode
其中代碼 – Steve