[英]How to suppress initialization warnings
由於編碼約定,有沒有辦法抑制初始化? 例如,第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;
這至少可以消除您的錯誤。
這不是警告,它會在編譯期間產生錯誤,因為您嘗試讀取局部變量rootView
但是如果inflater.inflate
拋出異常,它可能最終沒有值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.