简体   繁体   English

延迟加载在 android 中不起作用

[英]Lazy Loading Not Working in android

I show the images on listview and call lazy loadiing in list Adapter class, for the show images on list view it,s working fine .我在列表视图上显示图像并在列表适配器类中调用延迟加载,对于列表视图上的显示图像,它工作正常。 Means Images load properly.意味着图像加载正确。

But i implement list view on item click listener and image url pass to another class and again i call lazy loading same as list adapter class但是我在项目单击侦听器上实现列表视图并将图像 url 传递给另一个类,我再次调用与列表适配器类相同的延迟加载

   ` imageLoader.DisplayImage(strimg.trim(), imgview);`

Then error occur然后出现错误

java.lang.NullPointerException java.lang.NullPointerException

My Java Code我的 Java 代码

  public class Description extends Activity
    {
public ImageLoader imageLoader; 
ImageView imgview;
String strimg;
Context context=this;
TextView 
@Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.details);

    imgview= (ImageView) findViewById(R.id.descimg);
    try
    {
        Bundle bundle=getIntent().getExtras();
        if(bundle != null)
    {
        strimg= bundle.getString("ImageUrl");
        Log.d("DescImg", "strimg");

    }
    else {
        Toast.makeText(context, "Image"+strimg, Toast.LENGTH_LONG).show();
        Toast.makeText(context, "NUll", Toast.LENGTH_LONG).show();
    }

    Log.d("Desc", strimg);
          imageLoader.DisplayImage(strimg.trim(), imgview);

    }
    catch(Exception e)
    {
        Log.d("DescError"+e, strimg);
    }
}

Pass Image Url传递图片网址

listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
            Intent i= new Intent(PropertySearch.this,Description.class);
            i.putExtra("ImageUrl", strimage[position]);

            startActivity(i);

        }
        });

Please Suggest me How i can fix this problem请建议我如何解决这个问题

Thanks In Advance.提前致谢。

You have just declare your ImageLoader class variable您刚刚声明了ImageLoader类变量

public ImageLoader imageLoader; 

not initialize.不初始化。 So initialize it in onCreate() method like,所以在onCreate()方法中初始化它,例如,

imageLoader = new ImageLoader(Description.this);

You may be forget to initialize your imageLoader .您可能忘记初始化imageLoader Just initialize your ImageLoader in your onCreate as below:只需在您的onCreate初始化您的ImageLoader ,如下所示:

public ImageLoader imageLoader;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.details);

    imageLoader= new ImageLoader(this);

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM