有没有办法根据编码约定抑制初始化?例如,第 17 行有一个初始化警告。
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ArrayList<String> EntryText;
ArrayAdapter<String> listviewAdapter;
View rootView;
try {
rootView = inflater.inflate(R.layout.fragment_main, container, false);
}
catch (Exception e) {
Log.e("Sunshine Exception(onCreateView)", Integer.toString(Thread.currentThread().getStackTrace()[2].getLineNumber()), e);
}
return rootView;
}
}
最佳答案
显式将其设置为 null,以便编译器知道您知道自己在做什么。
View rootView = null;
这至少会消除你的错误。
关于java - 如何抑制初始化警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27761776/