Recently i am working on RecycleView nad Retrofit for Json practise. I have managed everything but when i run my app it crushed and shows that no adapter attached.
This is my MainActivity class
public class MainActivity extends AppCompatActivity{
public MyRecycleViewAdapter adapter;
public RecyclerView recyclerView;
List<Movie> movies;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
LinearLayoutManager llm= new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
recyclerView.setLayoutManager(llm);
ApiINterface apiINterface = ApiClient.getClient().create(ApiINterface.class);
Call<Movies> call = apiINterface.getSongList("just_added");
call.enqueue(new Callback<Movies>() {
@Override
public void onResponse(Call<Movies> call, Response<Movies> response) {
movies = response.body().getMovies();
adapter = new MyRecycleViewAdapter(MainActivity.this , movies);
recyclerView.setAdapter(adapter);
}
@Override
public void onFailure(Call<Movies> call, Throwable t) {
}
});
}}
And this is my Logcat:
06-14 17:05:21.16125804-25804/com.example.lolipop.retrofitexamplewithhindisong E/RecyclerView:
No adapter attached; skipping layout 06-14 17:05:21.331 25804-25804/com.example.lolipop.retrofitexamplewithhindisong E/RecyclerView: No adapter attached; skipping layout
06-14 17:05:21.371 25804-25804/com.example.lolipop.retrofitexamplewithhindisong E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException at com.example.lolipop.retrofitexamplewithhindisong.MainActivity$1.onResponse(MainActivity.java:45) at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5511)
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:1029)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796) at dalvik.system.NativeStart.main(Native Method)
What's the problem i can't find.