我有一个NullPointerException
,我无法看到我搞砸了我的代码。 :)
这是我的代码:
public class VideosAdapter extends RecyclerView.Adapter<VideosAdapter.VideoViewHolder> {
private List<Video> videos;
private int rowLayout;
private Context context;
public static class VideoViewHolder extends RecyclerView.ViewHolder {
RelativeLayout videoLayout;
TextView videoTitle;
TextView channelTitle;
public VideoViewHolder(View v) {
super(v);
videoLayout = (RelativeLayout) v.findViewById(R.id.videoLayout);
videoTitle = (TextView) v.findViewById(R.id.videoTitle);
channelTitle = (TextView) v.findViewById(R.id.channelTitle);
}
}
public VideosAdapter (List<Video> videos, int rowLayout, Context context) {
this.videos = videos;
this.rowLayout = rowLayout;
this.context = context;
}
@Override
public VideosAdapter.VideoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(rowLayout, parent, false);
return new VideoViewHolder(view);
}
@Override
public void onBindViewHolder(VideoViewHolder holder, int position) {
holder.channelTitle.setText(videos.get(position).getChannelTitle());
holder.videoTitle.setText(videos.get(position).getTitle());
}
@Override
public int getItemCount() {
return videos.size();
}
}
这是我的LogCat:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at tactivityplayinc.streamtube.Adapters.VideosAdapter.getItemCount(VideosAdapter.java:67)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:2938)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2619)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16271)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1560)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:668)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:735)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2501)
at android.view.View.measure(View.java:16271)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2182)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1330)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1541)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1227)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4995)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5279)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
我没有意识到我没有初始化或者其他什么,如果不解决这个问题,我就无法继续下去。