0
當我嘗試在使用構造函數的類中設置視圖時,出現java java.lang.NullPointerException錯誤。我看不到我在做什麼錯在這裏。這裏是我的代碼:在構造函數Android中設置視圖帶有片段
public class HomeFragment extends Fragment {
public HomeFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
// Define webview stuff
DataSelector dataSelector = new DataSelector(rootView);
dataSelector.getData();
-
public class DataSelector {
public View mRootView;
public DataSelector(View RootView){
mRootView = RootView;
}
TextView resultView = (TextView) mRootView.findViewById(R.id.result);
public void getData(){
...
你能修改你的帖子並添加正確答案嗎?我嘗試了很多..不知道怎樣正確地理解它:S認爲我仍然在做錯事,儘管我嘗試了你所說的話! – Markinson