QuickBlox 1:1聊天发送图像

时间:2014-04-23 09:43:33

标签: android imageview universal-image-loader quickblox

我想将图片发送给用户。能够检索图像网址。但是当我使用Universal Image Loader将其附加到ImageView时

public void displayImage(String imageurl, ImageView img) 
{
        Log.d("Chat ImageUrl", imageurl);

        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .cacheInMemory().cacheOnDisc()
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
                .displayer(new RoundedBitmapDisplayer(20)).build();

        // Load and display image
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                this).defaultDisplayImageOptions(options).build();
        ImageLoader.getInstance().init(config);
        ImageLoader.getInstance().displayImage(imageurl, img);
    }

抛出以下错误

04-23 12:38:46.600: E/AndroidRuntime(664): FATAL EXCEPTION: main
04-23 12:38:46.600: E/AndroidRuntime(664): java.lang.NullPointerException
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:100)
04-23 12:38:46.600: E/AndroidRuntime(664):  at com.quickblox.sample.chat.ui.activities.ChatActivity.displayImage(ChatActivity.java:167)
04-23 12:38:46.600: E/AndroidRuntime(664):  at com.quickblox.sample.chat.ui.adapters.ChatAdapter.applyImg(ChatAdapter.java:97)
04-23 12:38:46.600: E/AndroidRuntime(664):  at com.quickblox.sample.chat.ui.adapters.ChatAdapter.getView(ChatAdapter.java:81)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.AbsListView.obtainView(AbsListView.java:1430)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.ListView.makeAndAddView(ListView.java:1745)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.ListView.fillSpecific(ListView.java:1290)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.ListView.layoutChildren(ListView.java:1588)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.AbsListView.onLayout(AbsListView.java:1260)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.view.View.layout(View.java:7175)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.view.View.layout(View.java:7175)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.view.View.layout(View.java:7175)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.view.View.layout(View.java:7175)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.view.View.layout(View.java:7175)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.view.View.layout(View.java:7175)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.os.Looper.loop(Looper.java:130)
04-23 12:38:46.600: E/AndroidRuntime(664):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-23 12:38:46.600: E/AndroidRuntime(664):  at java.lang.reflect.Method.invokeNative(Native Method)
04-23 12:38:46.600: E/AndroidRuntime(664):  at java.lang.reflect.Method.invoke(Method.java:507)
04-23 12:38:46.600: E/AndroidRuntime(664):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-23 12:38:46.600: E/AndroidRuntime(664):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-23 12:38:46.600: E/AndroidRuntime(664):  at dalvik.system.NativeStart.main(Native Method)

请求

1 个答案:

答案 0 :(得分:1)

代码终于奏效了。摆脱了空指针