应用程序崩溃是由于inflator异常,invocationtargetexception,resoutce未找到异常

时间:2016-07-01 11:15:54

标签: android android-fragments appcompatactivity

我正在测试我的主要活动扩展appcompat活动的应用

在styles.xml中,我使用的主题是theme.appcompat.light.darkactionbar

我已将最新的appcompat v7库包含在我的gradle文件中

但崩溃在logcat中给出了几个例外

**但如果我将主题更改为theme.appcompat.light.noactionbar,该应用程序正常工作**

我的主要活动

public class MainActivity extends AppCompatActivity 
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if(savedInstanceState == null){
        getSupportFragmentManager().beginTransaction()
        .add(R.id.container, new ForecastFragment())
        .commit();
    }
}


}

forecastfragment.java

public class ForecastFragment extends Fragment
{

private ArrayAdapter<String> mForecastAdapter;

public ForecastFragment(){

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{


    View rootView = inflater.inflate(R.layout.fragment_main, null);

    String[] forecastArray ={
        "today = sunny 34|26", 
        "tomorrow = sunny 23|23",
        "day after 2moro = rainy 25|23",
        "testing = calm 23|23",
        "testing = calm 22|22",
        "testing = calm 21|21",
        "testing = calm 21|21"  
    };

    List<String> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray));

    mForecastAdapter = new ArrayAdapter<String>(
        getActivity(),
        R.layout.list_item_forecast,
        R.id.list_item_forecast_textview,
        weekForecast);

    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);

    return rootView;

}

}

活动main.xml

<FrameLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mycompany.myapp.MainActivity"
tools:ignore="MergeRootFrame"
android:id="@+id/container">

 </FrameLayout>

预测片段xml

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="64dp"
android:paddingRight="64dp"
android:paddingTop="16dp"
tools:context="com.mycompany.myapp.MainActivity">

<ListView
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/listview_forecast"/>

 </FrameLayout>

logcat的

07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               FATAL EXCEPTION: main
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.myapp/com.mycompany.myapp.MainActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.app.ActivityThread.access$700(ActivityThread.java:158)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.os.Handler.dispatchMessage(Handler.java:99)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.os.Looper.loop(Looper.java:176)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.app.ActivityThread.main(ActivityThread.java:5365)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at java.lang.reflect.Method.invokeNative(Native Method)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at java.lang.reflect.Method.invoke(Method.java:511)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at dalvik.system.NativeStart.main(Native Method)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.view.LayoutInflater.createView(LayoutInflater.java:619)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:693)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:395)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at com.mycompany.myapp.MainActivity.onCreate(MainActivity.java:19)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.app.Activity.performCreate(Activity.java:5326)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               ... 11 more
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               Caused by: java.lang.reflect.InvocationTargetException
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at java.lang.reflect.Constructor.constructNative(Native Method)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.view.LayoutInflater.createView(LayoutInflater.java:593)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               ... 25 more
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.content.res.Resources.loadDrawable(Resources.java:2842)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.content.res.Resources.getDrawable(Resources.java:1521)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:354)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:181)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:67)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.support.v7.widget.Toolbar.<init>(Toolbar.java:298)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.support.v7.widget.Toolbar.<init>(Toolbar.java:229)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               ... 28 more
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:917)
07-01 16:30:23.843 9655 9655 E     AndroidRuntime                               at android.graphics.drawable.Drawable.createFromXml(Drawable.java:858)

0 个答案:

没有答案