Error loading image using Volley

I created an ImageView programatically,then i have to add image to it from a URL.I used Volley methods,But it throws NullPointerException and the app closes,when i tried with drawable image its working fine,I have given the Logcat below.please help.

import...
    public class imageopen extends Activity {


        LinearLayout layout;
        LinearLayout.LayoutParams lparams;
        Intent intent = getIntent();
        String easy = "1";


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.imageopen);

            layout =new LinearLayout(this);
            lparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

            lparams.setMargins(0, 10, 0, 10);
            lparams.gravity=Gravity.CENTER;

            layout.setOrientation(LinearLayout.VERTICAL);
            layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));

            final ImageView imView = new ImageView(this);
            imView.setLayoutParams(lparams);
            imView.getLayoutParams().height = 600;
            imView.getLayoutParams().width = 600;

            ImageLoader imageLoader = AppController.getInstance().getImageLoader();


            imageLoader.get("http://sreeharsh.web44.net/images/image1.jpg", new ImageLoader.ImageListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("tttttttt", "Image Load Error: " + error.getMessage());
                }

                @Override
                public void onResponse(ImageLoader.ImageContainer response, boolean arg1) {
                    if (response.getBitmap() != null) {
                        // load image into imageview
                        imView.setImageBitmap(response.getBitmap());
                    }
                }
            });

            layout.addView(imView);


            setContentView(layout);


        }
    }

Logcat:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sreeharsh.saqavu/com.radix.saqavu.imageopen}: java.lang.NullPointerException
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
                at android.app.ActivityThread.access$600(ActivityThread.java:156)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:153)
                at android.app.ActivityThread.main(ActivityThread.java:5297)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:511)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
                at dalvik.system.NativeStart.main(Native Method)
         Caused by: java.lang.NullPointerException
                at com.radix.saqavu.imageopen.onCreate(imageopen.java:51)
                at android.app.Activity.performCreate(Activity.java:5122)
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
                at android.app.ActivityThread.access$600(ActivityThread.java:156)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
                at android.os.Handler.dispatchMessage(Handler.java:99)
                at android.os.Looper.loop(Looper.java:153)
                at android.app.ActivityThread.main(ActivityThread.java:5297)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:511)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
                at dalvik.system.NativeStart.main(Native Method)


Source: java

Leave a Reply