我已经看过类似的错误,但没有一个能帮助我。我有活动,我可以点击按钮从画廊放图片。因此,当我选择图片并尝试恢复活动时,我会收到此错误。
11-14 15:00:26.884: W/dalvikvm(19944): threadid=1: thread exiting with uncaught exception (group=0x40c4a1f8)
11-14 15:00:26.904: E/AndroidRuntime(19944): FATAL EXCEPTION: main
11-14 15:00:26.904: E/AndroidRuntime(19944): java.lang.RuntimeException: Unable to start activity ComponentInfo{rs.telegraf.io/rs.telegraf.io.MainActivitySendNews}: android.view.InflateException: Binary XML file line #133: Error inflating class fragment
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.app.ActivityThread.access$600(ActivityThread.java:123)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.os.Looper.loop(Looper.java:137)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.app.ActivityThread.main(ActivityThread.java:4424)
11-14 15:00:26.904: E/AndroidRuntime(19944): at java.lang.reflect.Method.invokeNative(Native Method)
11-14 15:00:26.904: E/AndroidRuntime(19944): at java.lang.reflect.Method.invoke(Method.java:511)
11-14 15:00:26.904: E/AndroidRuntime(19944): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
11-14 15:00:26.904: E/AndroidRuntime(19944): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
11-14 15:00:26.904: E/AndroidRuntime(19944): at dalvik.system.NativeStart.main(Native Method)
11-14 15:00:26.904: E/AndroidRuntime(19944): Caused by: android.view.InflateException: Binary XML file line #133: Error inflating class fragment
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-14 15:00:26.904: E/AndroidRuntime(19944): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
11-14 15:00:26.904: E/AndroidRuntime(19944): at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:119)
11-14 15:00:26.904: E/AndroidRuntime(19944): at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
11-14 15:00:26.904: E/AndroidRuntime(19944): at rs.telegraf.io.MainActivitySendNews.onCreate(MainActivitySendNews.java:145)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.app.Activity.performCreate(Activity.java:4465)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
11-14 15:00:26.904: E/AndroidRuntime(19944): ... 11 more
11-14 15:00:26.904: E/AndroidRuntime(19944): Caused by: java.lang.IllegalStateException: Fragment rs.telegraf.io.Fragment did not create a view.
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:303)
11-14 15:00:26.904: E/AndroidRuntime(19944): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
11-14 15:00:26.904: E/AndroidRuntime(19944): ... 24 more
我想也许我应该提前给我的碎片充气或类似这样的东西。还有一个有趣的事实,它只是偶尔发生,有时我会添加图片并正常返回MainActivitySendNews活动。这是我的xml文件,其中发生了异常,我的MainActivitySendNews类在其中创建了这个片段:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EEEEEE" >
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE" >
<RelativeLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<TextView
android:id="@+id/naslov_opis"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"
android:gravity="center_horizontal"
android:paddingTop="5dp"
android:text="@string/opis" />
<RelativeLayout
android:id="@+id/kategorija_opis"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/naslov_opis"
android:layout_marginTop="10dp" >
<TextView
android:id="@+id/izbor_kat_naslov"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/dodaj_kategorija" />
<View
android:id="@+id/prva_linija_naslov"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/izbor_kat_naslov"
android:background="#D5D5D5" />
<View
android:id="@+id/druga_linija_naslov"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/izbor_kat_naslov"
android:background="#D5D5D5" />
</RelativeLayout>
<Spinner
android:id="@+id/izbor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/kategorija_opis"
android:layout_marginBottom="50dp"
android:layout_marginTop="20dp"
android:gravity="center" />
<View
android:id="@+id/srednja"
android:layout_width="1dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:layout_marginTop="8dp"
android:background="#EEEEEE" />
<RelativeLayout
android:id="@+id/relative_odabir"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/izbor"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp" >
<TextView
android:id="@+id/dodaj"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/dodaj" />
<View
android:id="@+id/prva_linija"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/dodaj"
android:background="#D5D5D5" />
<View
android:id="@+id/duga_linija"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/dodaj"
android:background="#D5D5D5" />
</RelativeLayout>
<rs.telegraf.io.ExpandableHeightGridView
android:id="@+id/gridview"
android:layout_width="@dimen/grid_width"
android:layout_height="wrap_content"
android:layout_below="@id/relative_odabir"
android:layout_centerHorizontal="true"
android:background="#EEEEEE"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="3"
android:padding="0dp"
android:verticalSpacing="5dp" >
</rs.telegraf.io.ExpandableHeightGridView>
<fragment
android:id="@+id/fragment"
android:name="rs.telegraf.io.Fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/gridview"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
class="rs.telegraf.io.Fragment" >
</fragment>
<Button
android:id="@+id/odustani"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignRight="@id/srednja"
android:layout_below="@id/fragment"
android:layout_marginRight="@dimen/razma_dugmici"
android:background="@drawable/odustani_selector" />
<Button
android:id="@+id/posalji"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/srednja"
android:layout_below="@id/fragment"
android:layout_marginLeft="@dimen/razma_dugmici"
android:background="@drawable/posalji_selector" />
</RelativeLayout>
</ScrollView>
这是MainActivitySendNews的OnCreate方法:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.send_news_main);
pictureAlertWithContent.add(getResources().getDrawable(
R.drawable.item_click_send_new_camera));
pictureAlertWithContent.add(getResources().getDrawable(
R.drawable.item_click_send_new_galery));
pictureAlertWithContent.add(getResources().getDrawable(
R.drawable.item_click_send_new_delete));
pictureAlertEmpty.add(getResources().getDrawable(
R.drawable.item_click_send_new_camera));
pictureAlertEmpty.add(getResources().getDrawable(
R.drawable.item_click_send_new_galery));
pictureAlertEmpty.add(getResources().getDrawable(
R.drawable.item_click_send_new_delete));
ScrollView src = (ScrollView) findViewById(R.id.scroll);
src.setClickable(false);
cansel = (Button) findViewById(R.id.odustani);
cansel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
// kamera=(ImageButton)findViewById(R.id.kamera);
// galerija=(ImageButton)findViewById(R.id.galerija);
posalji = (Button) findViewById(R.id.posalji);
posalji.setVisibility(View.INVISIBLE);
// cansel.setVisibility(View.INVISIBLE);
// intent_for_galery = new Intent(this, ImageGridActivity.class);
imageItems = getData();
pictures.put("0", "empty");
pictures.put("1", "empty");
pictures.put("2", "empty");
pictures.put("3", "empty");
pictures.put("4", "empty");
pictures.put("5", "empty");
gridView = (ExpandableHeightGridView) findViewById(R.id.gridview);
customGridAdapter = new GridViewAdapter(this, R.layout.row_grid,
imageItems);
gridView.setAdapter(customGridAdapter);
gridView.setExpanded(true);
gridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
if ((pictures.get(String.valueOf(position)).equals("empty"))) {
dialog_choise = onCreateDialogSingleChoice(position);
dialog_choise.show();
} else {
dialog_choise = onCreateDialogSingleChoiceWithContent(position);
dialog_choise.show();
}
}
});
// lista za izbor vrste oglasa
spinner = (Spinner) findViewById(R.id.izbor);
fragmenti = new ArrayList<rs.telegraf.io.Fragment>();
adp = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, list_za_spinner);
dialog = new ProgressDialog(MainActivitySendNews.this);
dialog.setCanceledOnTouchOutside(false);
new load().execute("");
int i = getResources().getConfiguration().orientation;
if (i == Configuration.ORIENTATION_LANDSCAPE)
margine(i);
posalji.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
boolean for_send = true;
if (number_of_pictures != 6) {
userDetJson = new JSONObject();
userDetJsonArray = new JSONArray();
List<EditText> editboxesEditTexts = fragmenti.get(
position_spiner).getEditboxes();
List<String> parameters = fragmenti.get(position_spiner)
.getData().getParametri();
try {
for (int i = 0; i < editboxesEditTexts.size(); i++) {
String tmp = String.valueOf(parameters.get(i)
.charAt(0));
if (tmp.equals("*"))
{
if ((editboxesEditTexts.get(i).getText()
.toString()).equals("")) {
Toast.makeText(
getApplicationContext(),
getString(R.string.please)
+ " "
+ editboxesEditTexts.get(i)
.getHint(),
Toast.LENGTH_LONG).show();
for_send = false;
break;
}
else {
userDetJson.put(parameters.get(i),
editboxesEditTexts.get(i).getText());
}
} else {
userDetJson.put(parameters.get(i),
editboxesEditTexts.get(i).getText());
}
}
} catch (Exception e) {
}
} else {
for_send = false;
Toast.makeText(getApplicationContext(),
R.string.error_number_picture, Toast.LENGTH_LONG)
.show();
}
if (!pick_category) {
Toast.makeText(getApplicationContext(),
"Morate izabrati kategoriju", Toast.LENGTH_LONG)
.show();
}
if (for_send && pick_category) {
new SendData().execute();
finish();
}
}
});
}