Autore Topic: Problema Fragment  (Letto 768 volte)

Offline marcor91

  • Nuovo arrivato
  • *
  • Post: 6
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung s4mini
  • Sistema operativo:
    Windows 7
Problema Fragment
« il: 19 Marzo 2014, 14:21:22 CET »
0
Codice (Java): [Seleziona]
package com.efesto.mobile;

import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerFragment;
import com.google.android.youtube.player.YouTubePlayerView;
import com.google.android.youtube.player.YouTubePlayer.Provider;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

public class Youtube extends Fragment implements YouTubePlayer.OnInitializedListener{
        static private String VIDEO = "TD4iIuGfMY4";
       

    public Youtube() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.youtube, container, false);
        setHasOptionsMenu(true);
       
        YouTubePlayerFragment.newInstance();
       
                YouTubePlayerView youTubeView = (YouTubePlayerView) rootView.findViewById(R.id.youtube_view);
                youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
               
        return rootView;
    }
   
        @Override
        public void onInitializationFailure(Provider provider, YouTubeInitializationResult error) {
                System.out.println(error.toString());
        }
        @Override
        public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
                player.loadVideo(VIDEO);
        }
   
        @Override
        public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
                getActivity().getMenuInflater().inflate(R.menu.search, menu);
                super.onCreateOptionsMenu(menu, inflater);
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
                switch (item.getItemId()) {
                case R.id.search:
                        System.out.println("Hai schiacciato search");
                       
                        return true;
                }
                return super.onOptionsItemSelected(item);
        }


}

Codice (Java): [Seleziona]
                        Fragment fragment = new Youtube();
                        FragmentManager fragmentManager = getFragmentManager();
                        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

Ciao ragazzi vorrei integrare un video con un fragment ma non funziona, mi da un errore di Exception Inflater, mi potreste aiutare?

Offline a_droid

  • Nuovo arrivato
  • *
  • Post: 28
  • Respect: +5
    • Mostra profilo
Re:Problema Fragment
« Risposta #1 il: 19 Marzo 2014, 15:10:21 CET »
0
Ciao, potresti incollare il Logcat relativo all'errore e il codice corrispondente alla riga a cui l'eccezione fa riferimento?

Offline marcor91

  • Nuovo arrivato
  • *
  • Post: 6
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung s4mini
  • Sistema operativo:
    Windows 7
Re:Problema Fragment
« Risposta #2 il: 19 Marzo 2014, 16:19:16 CET »
0
FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #9: Error inflating class com.google.android.youtube.player.YouTubePlayerView
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:693)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.efesto.mobile.Youtube.onCreateView(Youtube.java:29)
at android.app.Fragment.performCreateView(Fragment.java:1699)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1075)
at android.app.BackStackRecord.run(BackStackRecord.java:682)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1455)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5306)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
t com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
... 20 more
Caused by: java.lang.IllegalStateException: A YouTubePlayerView can only be created with an Activity  which extends YouTubeBaseActivity as its context.
at com.google.android.youtube.player.YouTubePlayerView.<init>(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView.<init>(Unknown Source)
... 23 more

Offline a_droid

  • Nuovo arrivato
  • *
  • Post: 28
  • Respect: +5
    • Mostra profilo
Re:Problema Fragment
« Risposta #3 il: 19 Marzo 2014, 16:31:37 CET »
0
Io mi concentrerei su  questo errore :

Codice (Java): [Seleziona]
Caused by: java.lang.IllegalStateException: A YouTubePlayerView can only be created with an Activity  which extends YouTubeBaseActivity as its context.
La risposta dovrebbe essere qui :

android - How to play a video with the YouTube API using YouTubePlayerFragment? - Stack Overflow

L'activity che contiene il Fragment estende YouTubeBaseActivity?

Offline marcor91

  • Nuovo arrivato
  • *
  • Post: 6
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Samsung s4mini
  • Sistema operativo:
    Windows 7
Re:Problema Fragment
« Risposta #4 il: 19 Marzo 2014, 16:55:59 CET »
0
Estende Acitivity