Daftar dan Belajar Sekarang!

Ini kenapa ya ? padahal datanya ada diservernya tapi kok null

foto Mujiburrohman
9 Kontribusi 0 Coto
4 bulan yang lalu
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.mozeeb.schoolreport, PID: 24778 java.lang.RuntimeException: Unable to resume activity {com.mozeeb.schoolreport/com.mozeeb.schoolreport.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void java.util.List.clear()' on a null object reference at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3581) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2862) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void java.util.List.clear()' on a null object reference at com.mozeeb.schoolreport.user.NewsFragment.onResume(NewsFragment.java:112) at android.support.v4.app.Fragment.performResume(Fragment.java:2498) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1501) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269) at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:3241) at android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:223) at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:538) at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:527) at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:172) at android.app.Activity.performResume(Activity.java:7141) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3556) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2862)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6494)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)  Application terminated.
  • Lampirkan codenya atau screenshoot code bro - IfanZalukhu
  • nah setelah itu masalahnya selesai ada lagi bro ini masalahnya : ini kenapa ya? E/RecyclerView: No adapter attached; skipping layout - Mujiburrohman

Login untuk tulis komentar


Jawaban
foto Mujiburrohman
9 Kontribusi 0 Coto
4 bulan yang lalu
nah setelah itu masalahnya selesai ada lagi bro ini masalahnya : ini kenapa ya? E/RecyclerView: No adapter attached; skipping layout
  • Kalau dilihat dari errornya, Kayaknya Adapter recyclerView nya belum di attached. Sehingga tidak bisa nge binding data ke layout_item recyclerViewnya - IfanZalukhu

Login untuk tulis komentar


foto Mujiburrohman
9 Kontribusi 0 Coto
4 bulan yang lalu
ini kode saya bro coba di cek public class UserHomeFragment extends Fragment { @BindView(R.id.rv_main) RecyclerView rvMain; Unbinder unbinder; ApiService apiService; private AdapterLapor adapterLaporan; private List<DataItemLapor> dataItemsLaporanLapor; public UserHomeFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_home, container, false); unbinder = ButterKnife.bind(this, view); return view; } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); dataItemsLaporanLapor = new ArrayList<>(); FloatingActionButton fab = view.findViewById(R.id.fabMain); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getActivity().getApplication(), UserTambahActivity.class)); } }); } private void getData() { final ProgressDialog progressDialog = new ProgressDialog(getActivity()); progressDialog.setTitle("Loading.."); progressDialog.setMessage("Get data"); progressDialog.show(); apiService = ConfigRetrofit.getClient().create(ApiService.class); Call<ResponseLaporan> call = apiService.getLaporan(); call.enqueue(new Callback<ResponseLaporan>() { @Override public void onResponse(Call<ResponseLaporan> call, Response<ResponseLaporan> response) { progressDialog.dismiss(); if (response.isSuccessful()) { Toasty.success(getActivity(), response.message(), Toasty.LENGTH_LONG).show(); ResponseLaporan responseNews = response.body(); dataItemsLaporanLapor = responseNews.getData(); setUpList(dataItemsLaporanLapor); } } @Override public void onFailure(Call<ResponseLaporan> call, Throwable t) { Toasty.error(getActivity(), t.getMessage(), Toasty.LENGTH_LONG).show(); } }); } private void setUpList(List<DataItemLapor> dataItemsLaporanLapor) { rvMain.setHasFixedSize(true); rvMain.setLayoutManager(new LinearLayoutManager(getActivity())); adapterLaporan = new AdapterLapor(getActivity(), dataItemsLaporanLapor); rvMain.setAdapter(adapterLaporan); } @Override public void onResume() { super.onResume(); getData(); } @Override public void onDestroyView() { super.onDestroyView(); unbinder.unbind(); } }
  • kayaknya codingan saya itu udah bener, atau ada yang masih salah ya? yang lainnya bisa nampilin data tapi yang ini belum bisa padalah codingannya udah sama - Mujiburrohman

Login untuk tulis komentar


foto jajanpasar
5 Kontribusi 2 Coto
1 bulan yang lalu
@Override
public void onCreate() {
    rvMain.setHasFixedSize(true); 
    rvMain.setLayoutManager(new LinearLayoutManager(getActivity()));
    adapterLaporan = new AdapterLapor(getActivity(), null);   
    rvMain.setAdapter(adapterLaporan);
}
baris dimana kamu panggil setUpList(), ganti dengan:
adapterLaporan.setData(dataItemsLaporanLapor);


Login untuk diksusi di forum sekolah koding