Java 加载可拉伸成碎片
我有一个线性布局,我想设置一个可绘制的背景Java 加载可拉伸成碎片,java,android,Java,Android,我有一个线性布局,我想设置一个可绘制的背景 fragments.add(new FragmentTypeC().newInstance(getString(R.string.Historie6_header), R.drawable.london_old_stock_exchange)); 但是它说在这一行中抛出了一个NULLPointerException,并且找不到资源。这是我的oncreateview: View root = inflater.inflate(R.layout
fragments.add(new FragmentTypeC().newInstance(getString(R.string.Historie6_header), R.drawable.london_old_stock_exchange));
但是它说在这一行中抛出了一个NULLPointerException,并且找不到资源。这是我的oncreateview:
View root = inflater.inflate(R.layout.fragment_type_c, container, false);
webViewHeader = (WebView) root.findViewById(R.id.header_type_c);
imageLayout = (LinearLayout) root.findViewById(R.id.layout_type_c);
webViewHeader.loadDataWithBaseURL("file:///android_asset/", loadHTLMContentHeader(header), "text/html; charset=utf-8", "utf-8", null);
webViewHeader.setBackgroundColor(0x00000000);
imageLayout.setBackground(ResourcesCompat.getDrawable(getResources(), picId, null));
return root;
}
有人知道我怎么修吗?试试这个
imageLayout.setBackgroundResource(picId);
在哪个函数中,您试图设置backgroundDrawable,比如OnCreate或什么?我想imageLayout可能还没有初始化?@AdnanAmjad我已经编辑了我的帖子