我在Google Play商店中有一個應用程序。我通過Crashlytics/Fabric獲取崩潰通知,所以我沒有真正的LogCat來引用。另外,我無法弄清楚如何在我自己的系統上覆制這個錯誤。OnCreateView空指針異常
我從Crashlytics得到的錯誤如下:
com.company.appname.Fragment.onCreateView(Fragment.java:48)
下面是對相關細節類聲明:
import android.support.v4.app.Fragment;
public class MyTypeFragment extends Fragment {...
下面是從該片段的那部分的代碼:
44 mRestartButton = (Button)contentView.findViewById(R.id.restart_button);
45 mRestartButton.setTypeface(regularTf);
46 mRestartButton.setOnClickListener(new View.OnClickListener() {
47 @Override
48 public void onClick(View v) {
49 getFragmentManager().popBackStack("startingFragment", 0);
50 }
51 });
我覺得有趣的是崩潰報告列出崩潰作爲onCreateView()
方法的,但48行是對我的按鈕的onClickListener
的onClick()
方法的聲明。
我已經研究過以下問題:
他們都似乎預示着問題訪問了這個XML時所涉及到的不正確id
分段。我不認爲然而這就是問題所在,因爲這是該片段的XML部分(而且也只有一個該片段佈局):我用這個相同:
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
>
<Button
android:id="@+id/restart_button"
android:layout_gravity="right"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="Restart"
/>
一件事我的許多片段的範例。該應用程序的功能是鑽取一系列問題以獲得答案。 「重置」按鈕可以讓他們一路回到起點,而無需通過任何他們沿途看到的中間片段。每個片段上都有一個按鈕,其名稱爲R.id.reset_button
。正如我所說的,儘管如此,我試圖在我的這一方面複製這個問題,但無法弄清楚它是如何發生的。
我讀過一些東西,指出這個問題可能與某個片段與其活動分離有關,但我甚至嘗試過離開我的應用程序並返回,並且仍然無法複製此錯誤。
...或者也許佈局是平臺特定的...你提供的信息是不可能回答這個問題的...... – Selvin
@Selvin我不明白你的意思是什麼意思。你能否詳細說明一下?我只有每個片段的一個佈局。平臺如何改變事情? – mbm29414
http://developer.android.com/guide/practices/screens_support.html#qualifiers <你有什麼? (或其他像layout-vXX) – Selvin