1

I have looked at other questions with a similar error to mine but theirs seem to be a bit different.

In logcat I get this error. I have no clue how to solve this.

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

Here is my MainActivity

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);
    }
}

Any help would be appreciated.

placerholder_offline.xml

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center"
        android:padding="@dimen/global_keyline_s">

        <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" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textAppearance="@style/TextAppearance.WebViewApp.Subhead"
            android:text="@string/placeholder_offline" />

    </LinearLayout>
</ScrollView>

drawer_item.xml

    <?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>
1
  • You probably need to include the xml files you're referencing, such as this one: 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 Commented Nov 5, 2015 at 19:40

1 Answer 1

3

As the exception states, the issue is caused by your placeholder_offline.xml drawable, which apparently contains a <ScrollView> tag.

You cannot have a <ScrollView> (or any other View tags) inside drawable XML- either you inadvertently put a layout file in your drawable folder, or you need to re-evaluate what you are using that drawable for.

In your case, your placeholder_offline layout contains this:

<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" />

The android:src="@layout/placeholder_offline" attribute is invalid- android:src needs to refer to a drawable, not a layout.

Sign up to request clarification or add additional context in comments.

8 Comments

My placeholder_offline.xml is in layout. I don't have one in drawable.
Then you shouldn't be referencing it as a drawable and/or trying to use it in an ImageView.
I don't have any reference to placeholder_offline.xml in MainActivity though.
Please post the contents of your MainActivity layout, or whichever Fragment has the ImageView in it.
I put it in up there.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.