<small id='NRA8i'></small><noframes id='NRA8i'>

      <legend id='NRA8i'><style id='NRA8i'><dir id='NRA8i'><q id='NRA8i'></q></dir></style></legend>
    1. <tfoot id='NRA8i'></tfoot>
      <i id='NRA8i'><tr id='NRA8i'><dt id='NRA8i'><q id='NRA8i'><span id='NRA8i'><b id='NRA8i'><form id='NRA8i'><ins id='NRA8i'></ins><ul id='NRA8i'></ul><sub id='NRA8i'></sub></form><legend id='NRA8i'></legend><bdo id='NRA8i'><pre id='NRA8i'><center id='NRA8i'></center></pre></bdo></b><th id='NRA8i'></th></span></q></dt></tr></i><div id='NRA8i'><tfoot id='NRA8i'></tfoot><dl id='NRA8i'><fieldset id='NRA8i'></fieldset></dl></div>

        <bdo id='NRA8i'></bdo><ul id='NRA8i'></ul>

        java.lang.IndexOutOfBoundsException:索引 7 无效,大小为 7

        java.lang.IndexOutOfBoundsException: Invalid index 7, size is 7(java.lang.IndexOutOfBoundsException:索引 7 无效,大小为 7)
          <tbody id='AQYlr'></tbody>

            • <bdo id='AQYlr'></bdo><ul id='AQYlr'></ul>
              <i id='AQYlr'><tr id='AQYlr'><dt id='AQYlr'><q id='AQYlr'><span id='AQYlr'><b id='AQYlr'><form id='AQYlr'><ins id='AQYlr'></ins><ul id='AQYlr'></ul><sub id='AQYlr'></sub></form><legend id='AQYlr'></legend><bdo id='AQYlr'><pre id='AQYlr'><center id='AQYlr'></center></pre></bdo></b><th id='AQYlr'></th></span></q></dt></tr></i><div id='AQYlr'><tfoot id='AQYlr'></tfoot><dl id='AQYlr'><fieldset id='AQYlr'></fieldset></dl></div>
            • <legend id='AQYlr'><style id='AQYlr'><dir id='AQYlr'><q id='AQYlr'></q></dir></style></legend>

              1. <small id='AQYlr'></small><noframes id='AQYlr'>

                <tfoot id='AQYlr'></tfoot>

                  本文介绍了java.lang.IndexOutOfBoundsException:索引 7 无效,大小为 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试实现视图寻呼机,在我的视图寻呼机图像来自服务器,我能够显示和滚动但是当我到达最后一张图像时它显示错误并且应用程序崩溃了,以下是我的代码段

                  I am trying to implement view pager,in my view pager images comes from server,I am able to display and scroll but when i reach at last image it shows error and app got crash,following is my snippet code

                     public class Test_Pager extends Activity{
                  
                  
                  private String strtd;
                  String[] imgStr;
                  ImageView imageView;
                  ArrayList<String> userImgArrayList;
                  String[] myURLs;
                  
                  
                  /*country list*/
                  JSONArray country_list=null;
                  private ServiceHandler sh;
                  private String jsonStr;
                  private JSONObject jsonObj;
                  private String user_img;
                  private String user_pro;
                  private static String PROFILE_VIEW_URL = "";
                  
                  private static final String USER_IMG="product_images";
                  
                  
                  @Override
                  protected void onCreate(Bundle savedInstanceState) {
                      // TODO Auto-generated method stub
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.test_pagerss);
                  
                      userImgArrayList = getIntent().getStringArrayListExtra("user_images");
                      ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
                         ImageAdapter adapter = new ImageAdapter(this);
                         viewPager.setAdapter(adapter);
                  
                       imageView = (ImageView) findViewById(R.id.full_image_view);
                  
                  
                       PROFILE_VIEW_URL="";
                      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                      StrictMode.setThreadPolicy(policy);
                      sh = new ServiceHandler();
                  
                          // Making a request to url and getting response
                          jsonStr = sh.makeServiceCall(PROFILE_VIEW_URL, ServiceHandler.GET);
                  
                          Log.d("Response: ", "> " + jsonStr);
                  
                       try {
                           jsonObj = new JSONObject(jsonStr);
                  
                  
                               /*proview_business = jsonObj.getString(PROFILE_VIEW_BUSINESS);
                               proview_subcat = jsonObj.getString(PROFILE_VIEW_SUB_CATAGORY);
                               proview_mainpro = jsonObj.getString(PROFILE_VIEW_MAINPRODUCTS);
                               proview_expr = jsonObj.getString(PROFILE_VIEW_EXPERIENCE);
                               proview_cmpname = jsonObj.getString(PROFILE_VIEW_COMPANYNAME);
                               proview_website = jsonObj.getString(PROFILE_VIEW_WEBSITE);*/
                  
                              // user_img=jsonObj.getString(USER_IMG);
                  
                  
                  
                              user_img=jsonObj.getString(USER_IMG);
                              user_img = "";
                              userImgArrayList = new ArrayList<String>();//declare userImgArrayList globally like ArrayList<String> userImgArrayList;
                              JSONArray picarray = jsonObj.getJSONArray(USER_IMG);
                              for(int i=0;i< picarray.length();i++)
                              {
                                  user_img = picarray.getString(i);
                                  userImgArrayList.add(user_img);
                                  Log.d("mylog", "curent  pro pic  = " + user_img);
                              }
                  
                  
                       } catch (JSONException e) {
                           e.printStackTrace();
                       }
                  
                  }
                  public class ImageAdapter extends PagerAdapter {
                       Context context;
                        ImageAdapter(Context context)
                       {
                       this.context=context;
                       }
                        @Override
                        public int getCount() {
                        return USER_IMG.length();
                        }
                  
                        @Override
                          public void destroyItem(View container, int position, Object object) {
                               ((ViewPager) container).removeView((View) object);
                          }
                       @Override
                       public boolean isViewFromObject(View view, Object object) {
                       return view == ((ImageView) object);
                       }
                  
                       @Override
                          public Object instantiateItem(ViewGroup container, int position) {
                              ImageView imageView = new ImageView(context);
                              int padding = context.getResources().getDimensionPixelSize(
                                      R.dimen.activity_horizontal_margin);
                              imageView.setPadding(padding, padding, padding, padding);
                              //imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                              //Picasso.with(context).load(userImgArrayList.get(position)).into(imageView);
                              Picasso.with(context).load(userImgArrayList.get(position)).resize(200, 200) .into(imageView);
                  
                              /*for(int i=0; i<myURLs.length;i++)
                              { 
                  
                                  try {
                                      url = new URL(myURLs[i]);
                                  } catch (MalformedURLException e) {
                                      // TODO Auto-generated catch block
                                      e.printStackTrace();
                                  }
                  
                                  try {
                                      bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                                  } catch (IOException e) {
                                      // TODO Auto-generated catch block
                                      e.printStackTrace();
                                  }
                                   imageView.setImageBitmap(bmp);
                              }
                              */
                              // imageView.setImageURI(Uri.parse(imgStr[position]));
                              ((ViewPager) container).addView(imageView, 0);
                              return imageView;
                          }
                       }
                  
                    }
                  

                  我的xml

                          <RelativeLayout 
                           android:layout_height="wrap_content"
                           android:layout_width="wrap_content"
                           android:background="@android:color/white"
                           xmlns:android="http://schemas.android.com/apk/res/android">
                  
                  
                  
                  
                  
                  
                  
                         <ScrollView 
                             android:layout_height="match_parent"
                             android:layout_width="match_parent"
                              android:layout_below="@+id/lnr"
                              android:fillViewport="true"
                  
                                  >
                  
                             <LinearLayout 
                            android:layout_width="match_parent"
                             android:layout_height="match_parent"
                             android:orientation="vertical" >
                  
                              <LinearLayout 
                                  android:layout_height="wrap_content"
                                  android:layout_width="wrap_content"
                              android:orientation="vertical"
                                   >
                            <android.support.v4.view.ViewPager
                        android:id="@+id/view_pager"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
                  
                  <ImageView android:id="@+id/full_image_view"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"/></LinearLayout>
                  
                   <LinearLayout 
                      android:layout_height="wrap_content"
                      android:layout_width="fill_parent"
                      android:orientation="vertical"
                      android:background="@drawable/secondpart"
                      android:layout_marginLeft="5dp"
                      android:layout_marginRight="5dp"
                      android:layout_marginTop="5dp"
                      >
                        <TableLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:shrinkColumns="*"  android:stretchColumns="*" >
                         <TableRow
                                          android:layout_height="wrap_content"
                                          android:layout_width="wrap_content"
                                          android:gravity="center_horizontal">
                  
                          <TextView 
                              android:layout_height="wrap_content"
                              android:layout_width="fill_parent"
                              android:text="Product Name"
                              android:layout_marginLeft="5dp"
                              android:textColor="@android:color/black"
                              />
                  
                  
                          <TextView 
                              android:layout_height="wrap_content"
                              android:layout_width="fill_parent"
                              android:id="@+id/txtageprofile"
                  
                              android:textColor="@android:color/black"
                              android:layout_marginLeft="5dp"
                              /></TableRow>
                          <TableRow
                                          android:layout_height="wrap_content"
                                          android:layout_width="wrap_content"
                                          android:gravity="center_horizontal"
                                          android:paddingTop="5dp"
                                          >
                           <TextView 
                              android:layout_height="wrap_content"
                              android:layout_width="fill_parent"
                              android:text="Code"
                              android:layout_marginLeft="5dp"
                              android:textColor="@android:color/black"
                              />
                  
                  
                          <TextView 
                              android:layout_height="wrap_content"
                              android:layout_width="fill_parent"
                  
                              android:id="@+id/txtheightprofile"
                  
                            android:textColor="@android:color/black"
                            android:layout_marginLeft="5dp"
                              /></TableRow>
                           <TableRow
                                          android:layout_height="wrap_content"
                                          android:layout_width="wrap_content"
                                          android:gravity="center_horizontal"
                                          android:paddingTop="5dp"
                                          >
                           <TextView 
                              android:layout_height="wrap_content"
                              android:layout_width="fill_parent"
                              android:text="Purchase Rate"
                              android:layout_marginLeft="5dp"
                              android:textColor="@android:color/black"
                              />
                  
                  
                          <TextView 
                              android:layout_height="wrap_content"
                              android:layout_width="fill_parent"
                  
                              android:id="@+id/txtmrgprofile"
                  
                              android:textColor="@android:color/black"
                              android:layout_marginLeft="5dp"
                              /></TableRow>
                            <TableRow
                                          android:layout_height="wrap_content"
                                          android:layout_width="wrap_content"
                                          android:gravity="center_horizontal"
                                          android:paddingTop="5dp">
                           <TextView 
                              android:layout_height="wrap_content"
                              android:layout_width="fill_parent"
                              android:text="Weight"
                              android:layout_marginLeft="5dp"
                              android:textColor="@android:color/black"
                              />
                  
                           <TextView 
                              android:layout_height="wrap_content"
                              android:layout_width="fill_parent"
                  
                              android:id="@+id/txtworkingprofile"
                  
                              android:textColor="@android:color/black"
                              android:layout_marginLeft="5dp"
                              /></TableRow>
                             <TableRow
                                          android:layout_height="wrap_content"
                                          android:layout_width="wrap_content"
                                          android:gravity="center_horizontal"
                                          android:paddingTop="5dp"
                                          >
                           <TextView 
                              android:layout_height="wrap_content"
                              android:layout_width="fill_parent"
                              android:text="Sales Rate"
                              android:layout_marginLeft="5dp"
                              android:textColor="@android:color/black"
                              />
                  
                           <TextView 
                              android:layout_height="wrap_content"
                              android:layout_width="fill_parent"
                              android:id="@+id/txtplaceprofile"
                              android:textColor="@android:color/black"
                              android:layout_marginLeft="5dp"
                              /></TableRow>
                              </TableLayout>
                              </LinearLayout>
                             <LinearLayout 
                      android:layout_height="wrap_content"
                      android:layout_width="fill_parent"
                      android:orientation="vertical"
                      android:background="@drawable/secondpart"
                      android:layout_marginLeft="5dp"
                      android:layout_marginRight="5dp"
                      android:layout_marginTop="5dp"
                      >
                              <TextView 
                              android:layout_height="wrap_content"
                              android:layout_width="wrap_content"
                              android:layout_gravity="center_vertical|right"
                  
                              android:id="@+id/txteatprofile"
                              android:textColor="@android:color/black"
                              android:layout_marginLeft="5dp"
                             android:layout_marginRight="5dp"
                              />
                              </LinearLayout>
                  
                  
                        </LinearLayout>
                        </ScrollView>
                        </RelativeLayout>
                  

                  推荐答案

                  USER_IMG.length(); 返回String的长度("的字符数产品图像").您应该返回数据集的大小.改变

                  USER_IMG.length(); returns the length of the String (the number of chars of "product_images"). You should return the size of the data set instead. Change

                   @Override
                   public int getCount() {
                        return USER_IMG.length();
                   }
                  

                   @Override
                   public int getCount() {
                        if (userImgArrayList == null) {
                           return 0;
                        } 
                        return userImgArrayList.size();
                   }
                  

                  这篇关于java.lang.IndexOutOfBoundsException:索引 7 无效,大小为 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Android- listview, service mediaplayer, and boolean flags(Android-listview、服务媒体播放器和布尔标志)
                  SharedPreferences amp; boolean(SharedPreferences amp;布尔值)
                  What values should I use for iOS boolean states?(我应该为 iOS 布尔状态使用什么值?)
                  Converting Int to Bool(将 Int 转换为 Bool)
                  How do I get NSJSONSerialization to output a boolean as true or false?(如何让 NSJSONSerialization 将布尔值输出为真或假?)
                  Is there any difference between bool, Boolean, and BOOL in Objective-C?(Objective-C 中的 bool、Boolean 和 BOOL 之间有什么区别吗?)

                        <tbody id='ktTDq'></tbody>
                      <legend id='ktTDq'><style id='ktTDq'><dir id='ktTDq'><q id='ktTDq'></q></dir></style></legend>

                        <tfoot id='ktTDq'></tfoot>
                      • <small id='ktTDq'></small><noframes id='ktTDq'>

                        <i id='ktTDq'><tr id='ktTDq'><dt id='ktTDq'><q id='ktTDq'><span id='ktTDq'><b id='ktTDq'><form id='ktTDq'><ins id='ktTDq'></ins><ul id='ktTDq'></ul><sub id='ktTDq'></sub></form><legend id='ktTDq'></legend><bdo id='ktTDq'><pre id='ktTDq'><center id='ktTDq'></center></pre></bdo></b><th id='ktTDq'></th></span></q></dt></tr></i><div id='ktTDq'><tfoot id='ktTDq'></tfoot><dl id='ktTDq'><fieldset id='ktTDq'></fieldset></dl></div>

                            <bdo id='ktTDq'></bdo><ul id='ktTDq'></ul>