应用程序停止在Toast消息中显示错误

时间:2016-05-01 09:11:18

标签: android android-fragments android-imageview layout-inflater android-toast

突然显示我的应用程序在显示Toast消息时崩溃。 它以前工作得很好。

我有ImageView的片段,按钮下载该图片。我通过在临时位置下载并在imageview中显示来显示图像。如果用户点击保存图像,我只需重命名临时文件。

我记得我没有碰过这个片段代码和布局以及相关的类,但是正在修改其他文件并更新gradle和android studio到最新的2.1。 突然我的应用程序停止了异常,下面是我无法理解的logcat

还有一些其他地方正在显示吐司消息,现在出现错误。

我指的是这个链接 android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>

但不确定我应该采取什么步骤来解决这个奇怪的错误。

android.view.InflateException: Binary XML file line #21: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.widget.Toast.makeText(Toast.java:262)
at com.srids.sathyasaiinspires.FragmentImage$1.onClick(FragmentImage.java:78)
at android.view.View.performClick(View.java:4856)
at android.view.View$PerformClick.run(View.java:19956)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5389)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:482) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.widget.Toast.makeText(Toast.java:262) 
at com.srids.sathyasaiinspires.FragmentImage$1.onClick(FragmentImage.java:78) 
at android.view.View.performClick(View.java:4856) 
at android.view.View$PerformClick.run(View.java:19956) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:211) 
at android.app.ActivityThread.main(ActivityThread.java:5389) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815) 
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=6; index=6
at android.content.res.Resources.toPreloadCookie(Resources.java:2491)
at android.content.res.Resources.loadDrawable(Resources.java:2519)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3813)
at android.view.ViewGroup.<init>(ViewGroup.java:498)
at android.widget.LinearLayout.<init>(LinearLayout.java:200)
at android.widget.LinearLayout.<init>(LinearLayout.java:196)
at android.widget.LinearLayout.<init>(LinearLayout.java:192)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:482) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.widget.Toast.makeText(Toast.java:262)

我更新的gradle:

compile 'com.android.support:design:23.2.1'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'

以下是片段的xml文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView1"
        style="@style/btnStyleSandrift"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:layout_marginTop="30dp"
        android:background="@drawable/custom_btn_sandrift"
        android:contentDescription="@+id/cont_desc"
        android:src="@drawable/default_image" />

    <Button
        android:id="@+id/button1"
        style="@style/btnStyleSandrift"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/imageView1"
        android:layout_centerInParent="true"
        android:layout_marginTop="70dp"
        android:background="@drawable/custom_btn_sandrift"
        android:gravity="center"
        android:text="@string/SaveImage" />

</RelativeLayout>

FragmentImage.java文件Code实现onCreateView(),如下所示:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   // Inflate the layout for this fragment
   View rootView = inflater.inflate(R.layout.fragment_image, container, false);
   loader = R.drawable.default_image;
   imgview = (ImageView) rootView.findViewById(R.id.imageView1);

   urlImageString = getArguments().getString("URLIMAGESTRING");
   file_string = getArguments().getString("FILESTRING");

   imgLoader = new ImageLoader(super.getActivity().getApplicationContext());
   imgLoader.DisplayImage(urlImageString, loader, imgview, file_string);

   Button imgBtn = (Button) rootView.findViewById(R.id.button1);
   imgBtn.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
           // TODO Auto-generated method stub
           if (imgLoader.SaveImage(file_string)) {
               Toast.makeText(getActivity().getApplicationContext(), "Image saved...", Toast.LENGTH_LONG).show();
           } else {
               Toast.makeText(getActivity().getApplicationContext(), "Image not found...", Toast.LENGTH_LONG).show();
           }
       }
   });
   return rootView;
}

当应用程序在纵向模式下启动时,如果我点击保存它就会崩溃。在那之前,如果我旋转,加载land \ fragment_image.xml与相同的图像和按钮只是工作。放入纵向模式后,再没有崩溃。 这只发生在我的xperia Z中。在仿真器上,它运行得很好。

已确定修复:

我花了将近3天的时间来查看导致问题的原因,最后问题出现在appcompat-v7-23.2.1中 我更换了我的支持库,如下所示,一切正常。

    compile 'com.android.support:design:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'

我在下面提到的链接也是: https://code.google.com/p/android/issues/detail?id=201817

0 个答案:

没有答案