Я пытаюсь извлечь изображение из Url с помощью «Пикассо», но я получаю сообщение об ошибке в Мой LogCat какIllegalArgumentException ошибка в Android, контекст не должен быть пустым
причиненном: java.lang.IllegalArgumentException : Контекст не должен быть нулевым.
Ниже мой код и Logcat.
09-10 02:53:14.420 29527- 29527/green.example.tejask.asynctasknetworking I/art﹕ Late-enabling -Xcheck:jni
09-10 02:53:14.764 29527-29562/green.example.tejask.asynctasknetworking D/OpenGLRenderer﹕ Render dirty regions requested: true
09-10 02:53:14.788 29527-29527/green.example.tejask.asynctasknetworking D/﹕ HostConnection::get() New Host Connection established 0xabc8c8b0, tid 29527
09-10 02:53:14.799 29527-29527/green.example.tejask.asynctasknetworking D/Atlas﹕ Validating map...
09-10 02:53:14.879 29527-29562/green.example.tejask.asynctasknetworking D/libEGL﹕ loaded /system/lib/egl/libEGL_emulation.so
09-10 02:53:14.881 29527-29562/green.example.tejask.asynctasknetworking D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_emulation.so
09-10 02:53:14.894 29527-29562/green.example.tejask.asynctasknetworking D/libEGL﹕ loaded /system/lib/egl/libGLESv2_emulation.so
09-10 02:53:14.914 29527-29562/green.example.tejask.asynctasknetworking D/﹕ HostConnection::get() New Host Connection established 0xa3116120, tid 29562
09-10 02:53:14.962 29527-29562/green.example.tejask.asynctasknetworking I/OpenGLRenderer﹕ Initialized EGL, version 1.4
09-10 02:53:15.132 29527-29562/green.example.tejask.asynctasknetworking D/OpenGLRenderer﹕ Enabling debug mode 0
09-10 02:53:15.166 29527-29562/green.example.tejask.asynctasknetworking W/EGL_emulation﹕ eglSurfaceAttrib not implemented
09-10 02:53:15.166 29527-29562/green.example.tejask.asynctasknetworking W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3119220, error=EGL_SUCCESS
09-10 02:53:31.853 29527-29527/green.example.tejask.asynctasknetworking D/AndroidRuntime﹕ Shutting down VM
09-10 02:53:31.858 29527-29527/green.example.tejask.asynctasknetworking E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: green.example.tejask.asynctasknetworking, PID: 29527
java.lang.RuntimeException: Unable to start activity ComponentInfo{green.example.tejask.asynctasknetworking/green.example.tejask.asynctasknetworking.SecondActivity}: java.lang.IllegalArgumentException: Context must not be null.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalArgumentException: Context must not be null.
at com.squareup.picasso.Picasso$Builder.<init>(Picasso.java:701)
at com.squareup.picasso.Picasso.with(Picasso.java:662)
at green.example.tejask.asynctasknetworking.SecondActivity.onCreate(SecondActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
09-10 02:53:39.188 29527-29527/green.example.tejask.asynctasknetworking I/Process﹕ Sending signal. PID: 29527 SIG: 9
Это мой код:
package green.example.tejask.asynctasknetworking;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
/**
* Created by tejas k on 10-09-2015.
*/
public class SecondActivity extends AppCompatActivity {
private ImageView img;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String imgUri = "https://i.imgur.com/tGbaZCY.jpg";
img= (ImageView) findViewById(R.id.img);
Picasso.with(context).load(imgUri).into(img);
}
}
'IllegalArgumentException: Контекст не должен быть пустым, потому что' context' равно null. добавьте 'context = this' перед вызовом' Picasso.with' –