【问题标题】:Lazy Loading Not Working in android延迟加载在android中不起作用
【发布时间】:2014-04-10 11:55:43
【问题描述】:

我在列表视图上显示图像并在列表适配器类中调用延迟加载,以便在列表视图上显示图像,它工作正常。表示图片加载正常。

但我在项目单击侦听器上实现列表视图,并将图像 url 传递给另一个类,我再次调用与列表适配器类相同的延迟加载

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

然后出现错误

java.lang.NullPointerException

我的 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);
    }
}

传递图片网址

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);

        }
        });

请告诉我如何解决这个问题

提前致谢。

【问题讨论】:

  • 请发布您的代码!
  • 你在listview的自定义适配器中的点击监听?
  • 并发布您的 logcat 消息堆栈
  • 确保你得到值strimg 变量并且它不为空。
  • 看看我的回答。 @kuldeep

标签: android android-layout android-lazyadapter android-lazyloading


【解决方案1】:

你刚刚声明了你的 ImageLoader 类变量

public ImageLoader imageLoader; 

没有初始化。所以在 onCreate() 方法中初始化它,比如,

imageLoader = new ImageLoader(Description.this);

【讨论】:

    【解决方案2】:

    您可能忘记初始化您的imageLoader。 只需在您的onCreate 中初始化您的ImageLoader,如下所示:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-09
      • 2023-03-31
      相关资源
      最近更新 更多