我是片段的新手,具有以下代码:public class TripleTab1 extends Fragment {private TextView nameAndNumberText;private Map<String, String> nameToNumberMapping;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ nameAndNumberText = (TextView) getActivity().findViewById(R.id.numberToNameView); nameToNumberMapping = ContactNameAndNumberUtility .getNameToPhoneNumberMapping(getActivity() .getApplicationContext()); for (Map.Entry<String, String> item : nameToNumberMapping.entrySet()) { String key = item.getKey(); String value = item.getValue(); nameAndNumberText.append(key); nameAndNumberText.append(value); } return inflater.inflate(R.layout.assign_pattern_tab_1, container, false);}}不幸的是,这给了我一个NullPointerException。似乎TextView对象没有启动,即使我认为应该启动。“ java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'void android.widget.TextView.append(java.lang.CharSequence)'”有谁知道可能是错的吗?
添加回答
举报
0/150
提交
取消