Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
原因:android.view.InflateException:二进制XML文件行#15:对类android.widget.ImageView进行充气时出错_Android_Android Studio - Fatal编程技术网

原因:android.view.InflateException:二进制XML文件行#15:对类android.widget.ImageView进行充气时出错

原因:android.view.InflateException:二进制XML文件行#15:对类android.widget.ImageView进行充气时出错,android,android-studio,Android,Android Studio,我看过其他一些错误与我类似的问题,但它们似乎有点不同 在logcat中,我得到了这个错误。我不知道如何解决这个问题 11-05 13:10:04.211 30912-30912/? E/AndroidRuntime: FATAL EXCEPTION: main 11-05 13:10:04.211 30912-30912/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{c

我看过其他一些错误与我类似的问题,但它们似乎有点不同

在logcat中,我得到了这个错误。我不知道如何解决这个问题

11-05 13:10:04.211 30912-30912/? E/AndroidRuntime: FATAL EXCEPTION: main
11-05 13:10:04.211 30912-30912/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thesgn.app/com.thesgn.app.activity.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class android.widget.ImageView
11-05 13:10:04.211 30912-30912/? E/AndroidRuntime:  Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class android.widget.ImageView
11-05 13:10:04.211 30912-30912/? E/AndroidRuntime:  Caused by: java.lang.reflect.InvocationTargetException
11-05 13:10:04.211 30912-30912/? E/AndroidRuntime:  Caused by: android.content.res.Resources$NotFoundException: File res/layout/placeholder_offline.xml from drawable resource ID #0x7f03001b
11-05 13:10:04.211 30912-30912/? E/AndroidRuntime:  Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag ScrollView
这是我的主要活动

package com.thesgn.app.activity;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.thesgn.app.R;
import com.thesgn.app.WebViewAppApplication;
import com.thesgn.app.adapter.DrawerAdapter;
import com.thesgn.app.fragment.MainFragment;


public class MainActivity extends ActionBarActivity
{
    private DrawerLayout mDrawerLayout;
    private ActionBarDrawerToggle mDrawerToggle;
    private ListView mDrawerListView;

    private CharSequence mTitle;
    private CharSequence mDrawerTitle;
    private String[] mTitles;


    public static Intent newIntent(Context context)
    {
        Intent intent = new Intent(context, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        return intent;
    }


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setupActionBar();
        setupDrawer(savedInstanceState);

        // init analytics tracker
        ((WebViewAppApplication) getApplication()).getTracker();
    }


    @Override
    public void onStart()
    {
        super.onStart();

        // analytics
        GoogleAnalytics.getInstance(this).reportActivityStart(this);
    }


    @Override
    public void onResume()
    {
        super.onResume();
    }


    @Override
    public void onPause()
    {
        super.onPause();
    }


    @Override
    public void onStop()
    {
        super.onStop();

        // analytics
        GoogleAnalytics.getInstance(this).reportActivityStop(this);
    }


    @Override
    public void onDestroy()
    {
        super.onDestroy();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // action bar menu
        return super.onCreateOptionsMenu(menu);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        // open or close the drawer if home button is pressed
        if(mDrawerToggle.onOptionsItemSelected(item))
        {
            return true;
        }

        // action bar menu behaviour
        switch(item.getItemId())
        {
            case android.R.id.home:
                Intent intent = MainActivity.newIntent(this);
                startActivity(intent);
                return true;

            default:
                return super.onOptionsItemSelected(item);
        }
    }


    @Override
    protected void onPostCreate(Bundle savedInstanceState)
    {
        super.onPostCreate(savedInstanceState);
        mDrawerToggle.syncState();
    }


    @Override
    public void onConfigurationChanged(Configuration newConfiguration)
    {
        super.onConfigurationChanged(newConfiguration);
        mDrawerToggle.onConfigurationChanged(newConfiguration);
    }


    @Override
    public void setTitle(CharSequence title)
    {
        mTitle = title;
        getSupportActionBar().setTitle(mTitle);
    }


    private void setupActionBar()
    {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        ActionBar bar = getSupportActionBar();
        bar.setDisplayUseLogoEnabled(false);
        bar.setDisplayShowTitleEnabled(true);
        bar.setDisplayShowHomeEnabled(true);
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setHomeButtonEnabled(true);
    }


    private void setupDrawer(Bundle savedInstanceState)
    {
        mTitle = getTitle();
        mDrawerTitle = getTitle();

        // title list
        mTitles = getResources().getStringArray(R.array.navigation_title_list);

        // icon list
        TypedArray iconTypedArray = getResources().obtainTypedArray(R.array.navigation_icon_list);
        Integer[] icons = new Integer[iconTypedArray.length()];
        for(int i=0; i<iconTypedArray.length(); i++)
        {
            icons[i] = iconTypedArray.getResourceId(i, -1);
        }
        iconTypedArray.recycle();

        // reference
        mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_main_layout);
        mDrawerListView = (ListView) findViewById(R.id.activity_main_drawer);

        // set drawer
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
        mDrawerListView.setAdapter(new DrawerAdapter(this, mTitles, icons));
        mDrawerListView.setOnItemClickListener(new OnItemClickListener()
        {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View clickedView, int position, long id)
            {
                selectDrawerItem(position, false);
            }
        });
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close)
        {
            @Override
            public void onDrawerClosed(View view)
            {
                getSupportActionBar().setTitle(mTitle);
                supportInvalidateOptionsMenu();
            }

            @Override
            public void onDrawerOpened(View drawerView)
            {
                getSupportActionBar().setTitle(mDrawerTitle);
                supportInvalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        // show initial fragment
        if(savedInstanceState == null)
        {
            selectDrawerItem(0, true);
        }
    }


    private void selectDrawerItem(int position, boolean init)
    {
        String[] urlList = getResources().getStringArray(R.array.navigation_url_list);
        String[] shareList = getResources().getStringArray(R.array.navigation_share_list);

        Fragment fragment = MainFragment.newInstance(urlList[position], shareList[position]);
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.activity_main_container, fragment).commitAllowingStateLoss();

        mDrawerListView.setItemChecked(position, true);
        if(!init) setTitle(mTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerListView);
    }
}
package com.thesgn.app.activity;
导入android.content.Context;
导入android.content.Intent;
导入android.content.res.Configuration;
导入android.content.res.TypedArray;
导入android.os.Bundle;
导入android.support.v4.app.Fragment;
导入android.support.v4.app.FragmentManager;
导入android.support.v4.view.GravityCompat;
导入android.support.v4.widget.DrawerLayout;
导入android.support.v7.app.ActionBar;
导入android.support.v7.app.ActionBarActivity;
导入android.support.v7.app.ActionBarDrawerToggle;
导入android.support.v7.widget.Toolbar;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.ListView;
导入com.google.android.gms.analytics.GoogleAnalytics;
导入com.thesgn.app.R;
导入com.thesgn.app.webview应用程序;
导入com.thesgn.app.adapter.drauredapter;
导入com.thesgn.app.fragment.main片段;
公共类MainActivity扩展了ActionBarActivity
{
私人抽屉布局mDrawerLayout;
私有操作bardrawertoggle mDrawerToggle;
私有列表视图mDrawerListView;
私有字符序列mTitle;
私有字符序列mDrawerTitle;
私有字符串[]mTitles;
公共静态意图newIntent(上下文)
{
意向意向=新意向(上下文,MainActivity.class);
intent.addFlags(intent.FLAG\u ACTIVITY\u CLEAR\u TOP);
返回意图;
}
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupActionBar();
设置抽屉(savedInstanceState);
//初始分析跟踪器
((WebViewAppApplication)getApplication()).getTracker();
}
@凌驾
public void onStart()
{
super.onStart();
//分析
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@凌驾
恢复时公开作废()
{
super.onResume();
}
@凌驾
公共无效暂停()
{
super.onPause();
}
@凌驾
公共void onStop()
{
super.onStop();
//分析
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
@凌驾
公共空间
{
super.ondestory();
}
@凌驾
公共布尔onCreateOptions菜单(菜单)
{
//操作栏菜单
返回super.onCreateOptions菜单(菜单);
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项)
{
//如果按下“主页”按钮,则打开或关闭抽屉
如果(MDRAWERTOGLE.onOptionsItemSelected(项目))
{
返回true;
}
//动作栏菜单行为
开关(item.getItemId())
{
案例android.R.id.home:
Intent Intent=MainActivity.newIntent(此);
星触觉(意向);
返回true;
违约:
返回super.onOptionsItemSelected(项目);
}
}
@凌驾
后期创建时受保护的空(捆绑包savedInstanceState)
{
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@凌驾
公共无效OnConfiguration已更改(配置新建配置)
{
super.onConfigurationChanged(新配置);
mDrawerToggle.onConfiguration已更改(新配置);
}
@凌驾
公共无效设置标题(字符序列标题)
{
mTitle=标题;
getSupportActionBar().setTitle(mTitle);
}
私有void setupActionBar()
{
Toolbar Toolbar=(Toolbar)findViewById(R.id.Toolbar);
设置支持操作栏(工具栏);
ActionBar=getSupportActionBar();
bar.setDisplayUseLogoEnabled(false);
bar.setDisplayShowTitleEnabled(真);
bar.setDisplayShowHomeEnabled(真);
bar.setDisplayHomeAsUpEnabled(真);
bar.setHomeButtonEnabled(真);
}
专用void setupDrawer(Bundle savedInstanceState)
{
mTitle=getTitle();
mDrawerTitle=getTitle();
//标题列表
mTitles=getResources().getStringArray(R.array.navigation\u title\u list);
//图标列表
TypedArray iconTypedArray=getResources().obtainTypedArray(R.array.navigation\u icon\u list);
整数[]图标=新整数[iconTypedArray.length()];

对于(int i=0;i作为异常状态,问题是由
占位符\u offline.xml
drawable引起的,它显然包含一个
标记

您不能在可绘制XML中包含
(或任何其他视图标记)-可能是您无意中将布局文件放入了可绘制文件夹中,或者您需要重新评估使用该可绘制XML的目的

在您的情况下,
占位符\u脱机
布局包含以下内容:

<ImageView
    android:layout_width="@dimen/placeholder_image_size"
    android:layout_height="@dimen/placeholder_image_size"
    android:layout_marginBottom="@dimen/global_spacing_m"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    android:src="@layout/placeholder_offline" />


android的
src=“@layout/placeholder\u脱机”
属性无效-
android:src
需要引用可绘制文件,而不是布局。

您可能需要包含正在引用的xml文件,例如以下文件:
11-05 13:10:04.211 30912-30912/?E/AndroidRuntime:原因:org.xmlpull.v1.XmlPullParserException:二进制xml文件行#2:可绘制标记滚动视图无效我的占位符_offline.xml在布局中。我在drawable中没有占位符。那么,您不应该将其作为drawable引用和/或尝试在ImageView中使用它。不过,我在MainActivity中没有任何对占位符_offline.xml的引用。请发布您的MainActivity布局的内容,或者其他内容
    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="@dimen/global_spacing_l"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:background="?attr/drawerItemBackground">

    <ImageView
        android:id="@+id/drawer_item_icon"
        android:layout_width="@dimen/global_spacing_m"
        android:layout_height="@dimen/global_spacing_m"
        android:layout_marginLeft="@dimen/global_keyline_s"
        android:layout_marginRight="@dimen/global_spacing_xs"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter" />

    <TextView
        android:id="@+id/drawer_item_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="@dimen/global_keyline_s"
        android:textAppearance="@style/TextAppearance.WebViewApp.Body1" />

</LinearLayout>
<ImageView
    android:layout_width="@dimen/placeholder_image_size"
    android:layout_height="@dimen/placeholder_image_size"
    android:layout_marginBottom="@dimen/global_spacing_m"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    android:src="@layout/placeholder_offline" />