以前我有一个活动布局,我现在试图在片段中作为viewPager的一部分进行复制。我复制了旧的XML文件并在发生冲突时更改了所有ID。我为这个片段引用了新的XML布局,并创建了新的ID。但是当我运行它时,它会得到这个nullpointerexception。对于FindViewById,onCreate上的Java.Lang.Null.Pointer异常,可能是什么原因造成的?
这里是logcat的文件 http://i48.tinypic.com/14ekq6s.png
这里是在有错误发生java文件的一部分。
@Override
public RelativeLayout onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (container == null) {
// We have different layouts, and in one of them this
// fragment's containing frame doesn't exist. The fragment
// may still be created from its saved state, but there is
// no reason to try to create its view hierarchy because it
// won't be displayed. Note this is not needed -- we could
// just run the code below, where we would create and return
// the view hierarchy; it would just never be used.
return null;
}
inflater.inflate(R.layout.one, null);
ViewPager viewFinder = (ViewPager) getView();
//setContentView(R.layout.one);
title = (TextView) viewFinder.findViewById(R.id.frag_AA); //ERROR xml id file probz
这里是布局文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/frag_AA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="I Am Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
如果您现在先将布局名称调整为“one”,我可以接受此答案。对不起 –
当我回答你的问题时,它是'breed_frag1_layout'。但是这并不重要,你知道是什么原因导致了这个问题,以及如何解决这个问题。你的情况不公平,不公平的哥们。 :)如果将来我会看到你的问题,我会记住这种情况。 ;) –
我等了2天,只是想让帖子里的所有内容都一样。抱歉。你现在可以换掉吗? –