7 jun
2017

¿Cómo solucionar "la aplicacion se detuvo"?

Estoy desarrollando una aplicación en Android Studio y al correrla en el emulador se detiene antes de abrir nada. El caso es que si tengo el emulador configurado en español o en inglés (hay varios idiomas) funciona perfectamente, pero en catalán o cualquier otro idioma se detiene.

Este es el log del error:

05-24 09:07:22.114 3498-3498/com.example.juditmasana.batecs365
E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.example.juditmasana.batecs365, PID: 3498

java.lang.RuntimeException: Unable to start activity ComponentInfo{ com.example.juditmasana.batecs365/com.example.juditmasana.batecs365.MainActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #23: Error inflating class android.widget.ImageView

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)

... y así sigue un buen rato...

Este es el XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="MainActivity"
    tools:showIn="@layout/app_bar_main">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollView4" >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="1"
            android:layout_alignParentTop="true"
            android:layout_marginTop="0dp">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="28dp"></FrameLayout>

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:background="#000000">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="240dp"
                    android:layout_gravity="center">

                    <com.google.android.youtube.player.YouTubePlayerView
                        android:id="@+id/youtube_player"
                        android:layout_width="match_parent"
                        android:layout_height="240dp"
                        android:layout_marginBottom="30dp" />

                    <!--<ImageButton
                        android:layout_width="59dp"
                        android:layout_height="54dp"
                        android:id="@+id/play"
                        android:background="@drawable/play"
                        android:layout_gravity="center"
                        android:visibility="visible"/>-->
                </FrameLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:id="@+id/titleVideo"
                    android:textSize="20dp"
                    android:textStyle="bold"
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp"
                    android:textColor="#ffffff" />

            </LinearLayout>

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:weightSum="1"
                android:gravity="bottom">

                <Button
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="210dp"
                    android:layout_height="wrap_content"
                    android:text="@string/crea_el_teu_batec"
                    android:id="@+id/batecPropi"
                    android:background="@drawable/drawable_button"
                    android:textColor="#FFEBEE"
                    android:onClick="nouBatec"
                    android:layout_gravity="center"
                    android:layout_weight="0.31"
                    android:textSize="18dp"
                    android:textStyle="bold"
                    android:shadowColor="#cecece"
                    android:singleLine="true" />

            </LinearLayout>

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="30dp"></FrameLayout>

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom">

                <FrameLayout
                    android:layout_width="156dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/segueix_nos"
                        android:id="@+id/segueixXS"
                        android:textSize="15dp"
                        android:gravity="center_vertical"
                        android:layout_gravity="bottom|center_horizontal" />
                </FrameLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="bottom|right"
                    android:gravity="bottom|end">

                    <android.support.design.widget.FloatingActionButton
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:id="@+id/facebook"
                        android:layout_marginRight="5dp"
                        app:srcCompat="@drawable/ic_facebook"
                        android:scaleType="center"
                        app:backgroundTint="#3b5998"
                        android:layout_gravity="bottom|right" />

                    <android.support.design.widget.FloatingActionButton
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:id="@+id/twitter"
                        android:layout_marginRight="5dp"
                        app:srcCompat="@drawable/ic_twitter"
                        android:scaleType="center"
                        app:backgroundTint="#1dcaff"
                        android:layout_gravity="bottom|right"
                        android:paddingBottom="5dp" />

                    <android.support.design.widget.FloatingActionButton
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:id="@+id/youtube"
                        android:layout_gravity="bottom|right"
                        app:backgroundTint="#b31217"
                        app:srcCompat="@drawable/ic_youtube"
                        android:scaleType="center"/>

                </LinearLayout>
            </LinearLayout>

        </LinearLayout>
    </ScrollView>

</RelativeLayout>

... y este el código:

public class MainActivity extends YouTubeBaseActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    private YouTubePlayerView youTubePlayerView;
    private YouTubePlayer.OnInitializedListener onInitializedListener;
    private static final String API_KEY = "AIzaSyBl4SvN4KOuN2ImoLO4iRI0oTrHG4fxB9A";
    public String VIDEO_ID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        //setSupportActionBar(toolbar);

        //Create buttons social networks
        FloatingActionButton fcbk = (FloatingActionButton) findViewById(R.id.facebook);
        FloatingActionButton twttr = (FloatingActionButton) findViewById(R.id.twitter);
        FloatingActionButton utb = (FloatingActionButton) findViewById(R.id.youtube);
        fcbk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intentfcbk = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/solidaridadSJD/"));
                startActivity(intentfcbk);
            }
        });
        twttr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intenttwttr = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/solidaridadSJD"));
                startActivity(intenttwttr);
            }
        });
        utb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intentutb = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/user/obrasocialsjd"));
                startActivity(intentutb);
            }
        });

        //Declara el drawerLayout
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        //Controlador del Video de la pàgina principal
        youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player);
        onInitializedListener = new YouTubePlayer.OnInitializedListener() {
            public void onInitializationFailure(Provider provider, YouTubeInitializationResult result) {
            }
            public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
                /** add listeners to YouTubePlayer instance **/
                player.setPlayerStateChangeListener(playerStateChangeListener);
                player.setPlaybackEventListener(playbackEventListener);
                player.setShowFullscreenButton(true);
                /** Start buffering **/
                if (!wasRestored) {
                    player.cueVideo(VIDEO_ID);
                }
            }
        };
        new videoPlay(youTubePlayerView).execute("");

    }
    // Per poder agafar la informació de la pàgina www.365Batecs.org
    private class videoPlay extends AsyncTask<String, String, ArrayList<String>>{
        YouTubePlayerView myoutube;
        public videoPlay(YouTubePlayerView youTubePlayerView) {
            this.myoutube = youTubePlayerView;
        }
        @Override
        protected void onPreExecute(){
            super.onPreExecute();
        }
        protected ArrayList<String> doInBackground(String... params) {
            ArrayList<String> video = new ArrayList<>();
            String srcVideo;
            String title;
            try {
                Document doc = Jsoup.connect(getString(R.string.batecs_org)).get();
                Elements titleVideo = doc.select("iframe.youtube-field-player");
                title = titleVideo.attr("title");
                title = title.substring(25, title.length()-6);

                video.add(title);
                Log.e("Title", title);
                Elements videoPath = doc.select("iframe.youtube-field-player");
                srcVideo = videoPath.attr("src");
                srcVideo = srcVideo.substring(30, srcVideo.length() - 58);
                video.add(srcVideo);
                Log.e("Video: ",srcVideo);
                return video;

            }
            catch (IOException ex){
                ex.printStackTrace();
                Log.e("error", "HA SALTAT");
                return null;

            }
        }

        protected void onPostExecute(ArrayList<String> video){
            TextView titleVideo = (TextView) findViewById(R.id.titleVideo);
            if(video == null){
                final AlertDialog.Builder noConnection = new AlertDialog.Builder(MainActivity.this);
                noConnection.setTitle(R.string.sensecon);
                noConnection.setMessage(R.string.comprovila);
                noConnection.setIcon(R.drawable.ic_connection);
                noConnection.setPositiveButton(R.string.Tornarapr, new DialogInterface.OnClickListener(){
                    public void onClick(DialogInterface dialogInterface, int which){
                        new videoPlay(youTubePlayerView).execute("");
                    }
                });
                noConnection.create();
                noConnection.show();
            }
            else{
                titleVideo.append(video.get(0));
                VIDEO_ID =video.get(1);
                myoutube.initialize(API_KEY, onInitializedListener);
                Log.e("src: ", VIDEO_ID);
            }

            super.onPostExecute(video);
        }
    }

    private PlaybackEventListener playbackEventListener = new PlaybackEventListener() {
        @Override
        public void onBuffering(boolean arg0) {
        }
        @Override
        public void onPaused() {
        }
        @Override
        public void onPlaying() {
        }
        @Override
        public void onSeekTo(int arg0) {
        }
        @Override
        public void onStopped() {
        }
    };

    private PlayerStateChangeListener playerStateChangeListener = new PlayerStateChangeListener() {
        @Override
        public void onAdStarted() {
        }
        @Override
        public void onError(ErrorReason arg0) {
        }
        @Override
        public void onLoaded(String arg0) {
        }
        @Override
        public void onLoading() {
        }
        @Override
        public void onVideoEnded() {
        }
        @Override
        public void onVideoStarted() {
        }
    };

    //Botó per crear el teu nou batec
    public void nouBatec(View view){
        Intent instruc = new Intent(this, InstruccionsActivity.class);
        startActivity(instruc);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.

        return super.onOptionsItemSelected(item);
    }

    //Quan es selecciona una de les opcions del drawerLayaout
    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
       int id = item.getItemId();
       if (id == R.id.nav_info) {
            Intent info = new Intent(this,InformacioActivity.class);
            startActivity(info);

        }else if (id == R.id.nav_material) {
            Intent material = new Intent(this,MaterialActivity.class);
            startActivity(material);
        }
       else if (id == R.id.nav_ambit) {
            Intent ambit = new Intent(this,CercaAmbitActivity.class);
            ambit.putExtra("url","http://www.365batecs.org/sense-llar");
            ambit.putExtra("title", "Sense llar");
            startActivity(ambit);
        }
        else if (id==R.id.nav_app){
           Intent sobre_app = new Intent(this,SobreAppActivity.class);
           startActivity(sobre_app);
       }
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

COMENTARIOS

DEJA TU COMENTARIO

© 2017 website by Rubit Corporation