Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 导致内存泄漏错误的简单ViewPager应用程序_Android_Memory Leaks_Android Viewpager - Fatal编程技术网

Android 导致内存泄漏错误的简单ViewPager应用程序

Android 导致内存泄漏错误的简单ViewPager应用程序,android,memory-leaks,android-viewpager,Android,Memory Leaks,Android Viewpager,我试图制作一个简单的ViewPager应用程序示例,但我遇到了错误。我认为这是图像分辨率的问题,但在将ImageView更改为TextView并在其上编写示例文本后,我得到了相同的错误。(评论后,ViewPAger实现工作正常) 通道“2d5df67 com.example.k.myapplication/com.example.k.myapplication.MainActivity(服务器)”~通道已不可恢复地断开,将被处置 public类MainActivity扩展了AppCompatAc

我试图制作一个简单的ViewPager应用程序示例,但我遇到了错误。我认为这是图像分辨率的问题,但在将ImageView更改为TextView并在其上编写示例文本后,我得到了相同的错误。(评论后,ViewPAger实现工作正常)

通道“2d5df67 com.example.k.myapplication/com.example.k.myapplication.MainActivity(服务器)”~通道已不可恢复地断开,将被处置

public类MainActivity扩展了AppCompatActivity{
名单;
查看页面查看页面;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
列表=新的ArrayList();
列表。添加(“https://www.w3schools.com/css/trolltunga.jpg");
列表。添加(“http://www.esa.int/var/esa/storage/images/esa_multimedia/images/2016/03/ultraviolet_image_shows_the_sun_s_intricate_atmosphere/15891756-1-eng-GB/Ultraviolet_image_shows_the_Sun_s_intricate_atmosphere_node_full_image_2.jpg");
列表。添加(“http://pnge.org/wp-content/uploads/2017/03/1488980395_548_image.jpg");
列表。添加(“http://pnge.org/wp-content/uploads/2017/03/image.png");
列表。添加(“https://www.w3schools.com/css/trolltunga.jpg");
列表。添加(“http://www.esa.int/var/esa/storage/images/esa_multimedia/images/2016/03/ultraviolet_image_shows_the_sun_s_intricate_atmosphere/15891756-1-eng-GB/Ultraviolet_image_shows_the_Sun_s_intricate_atmosphere_node_full_image_2.jpg");
列表。添加(“http://pnge.org/wp-content/uploads/2017/03/1488980395_548_image.jpg");
列表。添加(“http://pnge.org/wp-content/uploads/2017/03/image.png");
viewPager=(viewPager)findViewById(R.id.viewPager);
ViewPAgerAdapter适配器=新的ViewPAgerAdapter(MainActivity.this,list);
viewPager.setAdapter(适配器);
}}
适配器类

public class ViewPAgerAdapter extends PagerAdapter {

    private List<String> record;
    private Context context;
   private LayoutInflater inflater;
    public ViewPAgerAdapter(Context context, List<String>record) {
        this.record=record;
        this.context=context;
        inflater=(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        View view = inflater.inflate(R.layout.item,container);

        ImageView img = (ImageView)view.findViewById(R.id.image);
      Glide.with(context).load(record.get(position)).fitCenter().into(img);

        container.addView(view);
        return view;
    }

    @Override
    public int getCount() {
        return record.size();
    }

    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((LinearLayout) object);
    }
}
public类ViewPAgerAdapter扩展了PagerAdapter{
私人名单记录;
私人语境;
私人充气机;
public ViewPAgerAdapter(上下文,列表记录){
这个.记录=记录;
this.context=context;
充气器=(LayoutFlater)context.getSystemService(context.LAYOUT\u充气器\u服务);
}
@凌驾
公共对象实例化项(视图组容器,int位置){
视图=充气机。充气(右布局。项目,容器);
ImageView img=(ImageView)view.findViewById(R.id.image);
Glide.with(context).load(record.get(position)).fitCenter()放入(img);
container.addView(视图);
返回视图;
}
@凌驾
public int getCount(){
返回记录。size();
}
@凌驾
public int getItemPosition(对象){
返回super.getItemPosition(对象);
}
@凌驾
公共布尔值isViewFromObject(视图,对象){
返回视图==((LinearLayout)对象);
}
}
项目布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/image"
    />
</LinearLayout>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    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="com.example.k.myapplication.MainActivity">


<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/viewPAger"/>
</LinearLayout>

活动布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/image"
    />
</LinearLayout>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    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="com.example.k.myapplication.MainActivity">


<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/viewPAger"/>
</LinearLayout>


尝试将其添加到您的清单中——android:configChanges=“keyboard | keyboardHidden | orientation | screenLayout | uiMode | Screen Size | Smallest Screen Size | mcc | mnc”

您是否尝试过frescoits而不是图像库故障。我试图用简单的文本视图替换我的ImageView,并使用页面计数,但得到了相同的错误