Android: android.view.InflateException: Binary XML file line #6: Error inflating class fragment



my files:



public class MainActivity extends ActionBarActivity implements YouTubePlayer.OnFullscreenListener {

/** The duration of the animation sliding up the video in portrait. */
private static final int ANIMATION_DURATION_MILLIS = 300;
/** The padding between the video list and the video in landscape orientation. */
private static final int LANDSCAPE_VIDEO_PADDING_DP = 5;
private VideoFragment videoFragment;

private View videoBox;
private View closeButton;

private boolean isFullscreen;


private VideoListFragment listFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
setContentView(R.layout.video_list_demo);
listFragment = (VideoListFragment)getSupportFragmentManager().findFragmentById(R.id.list_fragment);
videoFragment =
(VideoFragment) getSupportFragmentManager().findFragmentById(R.id.video_fragment_container);

videoBox = findViewById(R.id.video_box);
closeButton = findViewById(R.id.close_button);

videoBox.setVisibility(View.INVISIBLE);

layout();
//Intent i=new Intent(MainActivity.this,VideoListDemoActivity.class);
//startActivity(i);
}
@Override
public void onFullscreen(boolean isFullscreen) {
this.isFullscreen = isFullscreen;

layout();
}

/**
* Sets up the layout programatically for the three different states. Portrait, landscape or
* fullscreen+landscape. This has to be done programmatically because we handle the orientation
* changes ourselves in order to get fluent fullscreen transitions, so the xml layout resources
* do not get reloaded.
*/
private void layout() {
boolean isPortrait =
getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;

listFragment.getView().setVisibility(isFullscreen ? View.GONE : View.VISIBLE);
listFragment.setLabelVisibility(isPortrait);
closeButton.setVisibility(isPortrait ? View.VISIBLE : View.GONE);

if (isFullscreen) {
videoBox.setTranslationY(0); // Reset any translation that was applied in portrait.
setLayoutSize(videoFragment.getView(), MATCH_PARENT, MATCH_PARENT);
setLayoutSizeAndGravity(videoBox, MATCH_PARENT, MATCH_PARENT, Gravity.TOP | Gravity.LEFT);
} else if (isPortrait) {
setLayoutSize(listFragment.getView(), MATCH_PARENT, MATCH_PARENT);
setLayoutSize(videoFragment.getView(), MATCH_PARENT, WRAP_CONTENT);
setLayoutSizeAndGravity(videoBox, MATCH_PARENT, WRAP_CONTENT, Gravity.BOTTOM);
} else {
videoBox.setTranslationY(0); // Reset any translation that was applied in portrait.
int screenWidth = dpToPx(getResources().getConfiguration().screenWidthDp);
setLayoutSize(listFragment.getView(), screenWidth / 4, MATCH_PARENT);
int videoWidth = screenWidth - screenWidth / 4 - dpToPx(LANDSCAPE_VIDEO_PADDING_DP);
setLayoutSize(videoFragment.getView(), videoWidth, WRAP_CONTENT);
setLayoutSizeAndGravity(videoBox, videoWidth, WRAP_CONTENT,
Gravity.RIGHT | Gravity.CENTER_VERTICAL);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@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.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

private int dpToPx(int dp) {
return (int) (dp * getResources().getDisplayMetrics().density + 0.5f);
}

private static void setLayoutSize(View view, int width, int height) {
LayoutParams params = view.getLayoutParams();
params.width = width;
params.height = height;
view.setLayoutParams(params);
}

private static void setLayoutSizeAndGravity(View view, int width, int height, int gravity) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
params.width = width;
params.height = height;
params.gravity = gravity;
view.setLayoutParams(params);
}


public void onClickClose(@SuppressWarnings("unused") View view) {
listFragment.getListView().clearChoices();
listFragment.getListView().requestLayout();
videoFragment.pause();
videoBox.animate()
.translationYBy(videoBox.getHeight())
.setDuration(ANIMATION_DURATION_MILLIS)
.withEndAction(new Runnable() {
@Override
public void run() {
videoBox.setVisibility(View.INVISIBLE);
}
});
}
}


/*PageAdapter class*/

public class PageAdapter extends BaseAdapter {

private static final String DeveloperKey = "AIzaSyDZLd9_5IlwOGby_9SoS5q3Xi6pOo-HvRw";
private final List<VideoEntry> entries;
private final List<View> entryViews;
private final Map<YouTubeThumbnailView, YouTubeThumbnailLoader> thumbnailViewToLoaderMap;
private final LayoutInflater inflater;
private final ThumbnailListener thumbnailListener;

private boolean labelsVisible;

public PageAdapter(Context context, List<VideoEntry> entries) {
this.entries = entries;

entryViews = new ArrayList<View>();
thumbnailViewToLoaderMap = new HashMap<YouTubeThumbnailView, YouTubeThumbnailLoader>();
inflater = LayoutInflater.from(context);
thumbnailListener = new ThumbnailListener();

labelsVisible = true;
}

public void releaseLoaders() {
for (YouTubeThumbnailLoader loader : thumbnailViewToLoaderMap.values()) {
loader.release();
}
}

public void setLabelVisibility(boolean visible) {
labelsVisible = visible;
for (View view : entryViews) {
view.findViewById(R.id.text).setVisibility(visible ? View.VISIBLE : View.GONE);
}
}


public int getCount() {
return entries.size();
}


public VideoEntry getItem(int position) {
return entries.get(position);
}


public long getItemId(int position) {
return 0;
}


public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
VideoEntry entry = entries.get(position);

// There are three cases here
if (view == null) {
// 1) The view has not yet been created - we need to initialize the YouTubeThumbnailView.
view = inflater.inflate(R.layout.video_list_item, parent, false);
YouTubeThumbnailView thumbnail = (YouTubeThumbnailView) view.findViewById(R.id.thumbnail);
thumbnail.setTag(entry.videoId);
thumbnail.initialize(DeveloperKey, thumbnailListener);
} else {
YouTubeThumbnailView thumbnail = (YouTubeThumbnailView) view.findViewById(R.id.thumbnail);
YouTubeThumbnailLoader loader = thumbnailViewToLoaderMap.get(thumbnail);
if (loader == null) {
// 2) The view is already created, and is currently being initialized. We store the
// current videoId in the tag.
thumbnail.setTag(entry.videoId);
} else {
// 3) The view is already created and already initialized. Simply set the right videoId
// on the loader.
thumbnail.setImageResource(R.drawable.loading_thumbnail);
loader.setVideo(entry.videoId);
}
}
TextView label = ((TextView) view.findViewById(R.id.text));
label.setText(entry.text);
label.setVisibility(labelsVisible ? View.VISIBLE : View.GONE);
return view;
}

private final class ThumbnailListener implements
YouTubeThumbnailView.OnInitializedListener,
YouTubeThumbnailLoader.OnThumbnailLoadedListener {

@Override
public void onInitializationSuccess(
YouTubeThumbnailView view, YouTubeThumbnailLoader loader) {
loader.setOnThumbnailLoadedListener(this);
thumbnailViewToLoaderMap.put(view, loader);
view.setImageResource(R.drawable.loading_thumbnail);
String videoId = (String) view.getTag();
loader.setVideo(videoId);
}

@Override
public void onInitializationFailure(
YouTubeThumbnailView view, YouTubeInitializationResult loader) {
view.setImageResource(R.drawable.no_thumbnail);
}

@Override
public void onThumbnailLoaded(YouTubeThumbnailView view, String videoId) {
}

@Override
public void onThumbnailError(YouTubeThumbnailView view, ErrorReason errorReason) {
view.setImageResource(R.drawable.no_thumbnail);
}


}

}
/*A video List Fragment */
public class VideoListFragment extends ListFragment {

private static final List<VideoEntry> VIDEO_LIST;
static {
List<VideoEntry> list = new ArrayList<VideoEntry>();
list.add(new VideoEntry("YouTube Collection", "Y_UmWdcTrrc"));
list.add(new VideoEntry("GMail Tap", "1KhZKNZO8mQ"));
list.add(new VideoEntry("Chrome Multitask", "UiLSiqyDf4Y"));
list.add(new VideoEntry("Google Fiber", "re0VRK6ouwI"));
list.add(new VideoEntry("Autocompleter", "blB_X38YSxQ"));
list.add(new VideoEntry("GMail Motion", "Bu927_ul_X0"));
list.add(new VideoEntry("Translate for Animals", "3I24bSteJpw"));
VIDEO_LIST = Collections.unmodifiableList(list);
}

private PageAdapter adapter;
private View videoBox;

public VideoListFragment()
{

}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new PageAdapter(getActivity(), VIDEO_LIST);
}


public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

videoBox = getActivity().findViewById(R.id.video_box);
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
setListAdapter(adapter);
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
String videoId = VIDEO_LIST.get(position).videoId;

VideoFragment videoFragment =
(VideoFragment) getFragmentManager().findFragmentById(R.id.video_fragment_container);

videoFragment.setVideoId(videoId);

// The videoBox is INVISIBLE if no video was previously selected, so we need to show it now.
if (videoBox.getVisibility() != View.VISIBLE) {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
// Initially translate off the screen so that it can be animated in from below.
videoBox.setTranslationY(videoBox.getHeight());
}
videoBox.setVisibility(View.VISIBLE);
}

// If the fragment is off the screen, we animate it in.
if (videoBox.getTranslationY() > 0) {
videoBox.animate().translationY(0).setDuration(300);
}
}
@Override
public void onDestroyView() {
super.onDestroyView();

adapter.releaseLoaders();
}

public void setLabelVisibility(boolean visible) {
adapter.setLabelVisibility(visible);
}

}



/*VideoFragment

public class VideoFragment extends YouTubePlayerSupportFragment
implements OnInitializedListener {

private YouTubePlayer player;
private String videoId;

public static VideoFragment newInstance() {
return new VideoFragment();
}


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

initialize(DeveloperKey.DEVELOPER_KEY, this);
}

@Override
public void onDestroy() {
if (player != null) {
player.release();
}
super.onDestroy();
}

public void setVideoId(String videoId) {
if (videoId != null && !videoId.equals(this.videoId)) {
this.videoId = videoId;
if (player != null) {
player.cueVideo(videoId);
}
}
}

public void pause() {
if (player != null) {
player.pause();
}
}




@Override
public void onInitializationFailure(
com.google.android.youtube.player.YouTubePlayer.Provider arg0,
YouTubeInitializationResult arg1) {
// TODO Auto-generated method stub
this.player = null;
}


@Override
public void onInitializationSuccess(
com.google.android.youtube.player.YouTubePlayer.Provider provider,
YouTubePlayer player, boolean restored) {
// TODO Auto-generated method stub
this.player = player;
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
player.setOnFullscreenListener((MainActivity) getActivity());
if (!restored && videoId != null) {
player.cueVideo(videoId);
}

}


}
/*VideoEntry class
public class VideoEntry {

String text;
String videoId;

public VideoEntry(String text, String videoId) {
this.text = text;
this.videoId = videoId;
}
}

public class DeveloperKey {




public static final String DEVELOPER_KEY ="";

}


Errors



08-25 23:30:40.714: E/AndroidRuntime(281): FATAL EXCEPTION: main
08-25 23:30:40.714: E/AndroidRuntime(281): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.youtube8/com.example.youtube8.VideoListDemoActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
08-25 23:30:40.714: E/AndroidRuntime(281): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.os.Handler.dispatchMessage(Handler.java:99)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.os.Looper.loop(Looper.java:123)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-25 23:30:40.714: E/AndroidRuntime(281): at java.lang.reflect.Method.invokeNative(Native Method)
08-25 23:30:40.714: E/AndroidRuntime(281): at java.lang.reflect.Method.invoke(Method.java:521)
08-25 23:30:40.714: E/AndroidRuntime(281): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-25 23:30:40.714: E/AndroidRuntime(281): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-25 23:30:40.714: E/AndroidRuntime(281): at dalvik.system.NativeStart.main(Native Method)
08-25 23:30:40.714: E/AndroidRuntime(281): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
08-25 23:30:40.714: E/AndroidRuntime(281): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.view.LayoutInflater.inflate(LayoutInflater.java:382)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:128)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
08-25 23:30:40.714: E/AndroidRuntime(281): at com.example.youtube8.VideoListDemoActivity.onCreate(VideoListDemoActivity.java:70)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-25 23:30:40.714: E/AndroidRuntime(281): ... 11 more
08-25 23:30:40.714: E/AndroidRuntime(281): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.youtube8-2.apk]
08-25 23:30:40.714: E/AndroidRuntime(281): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
08-25 23:30:40.714: E/AndroidRuntime(281): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
08-25 23:30:40.714: E/AndroidRuntime(281): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
08-25 23:30:40.714: E/AndroidRuntime(281): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
08-25 23:30:40.714: E/AndroidRuntime(281): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
08-25 23:30:40.714: E/AndroidRuntime(281): ... 20 more





/*this is my xml files

Video_list_item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="95dp"
android:orientation="horizontal"
android:gravity="center"
>

<com.google.android.youtube.player.YouTubeThumbnailView
android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/no_thumbnail"
android:adjustViewBounds="true"
android:scaleType="centerInside"/>

<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"/>

</LinearLayout>

Video_list_demo XML File:

<merge xmlns:android="http://ift.tt/nIICcg"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment
class="com.examples.youtube8.VideoListFragment"
android:id="@+id/list_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>


<LinearLayout
android:id="@+id/video_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">

<ImageButton
android:id="@+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@android:drawable/btn_dialog"
android:onClick="onClickClose"/>

<fragment
class="com.examples.youtube8.VideoFragment"

android:id="@+id/video_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</LinearLayout>

</merge>


/*this is my xml files



Video_list_item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="95dp"
android:orientation="horizontal"
android:gravity="center"
>

<com.google.android.youtube.player.YouTubeThumbnailView
android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/no_thumbnail"
android:adjustViewBounds="true"
android:scaleType="centerInside"/>

<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff"/>

</LinearLayout>

Video_list_demo XML File:

<merge xmlns:android="http://ift.tt/nIICcg"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment
class="com.examples.youtube8.VideoListFragment"
android:id="@+id/list_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>


<LinearLayout
android:id="@+id/video_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">

<ImageButton
android:id="@+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@android:drawable/btn_dialog"
android:onClick="onClickClose"/>

<fragment
class="com.examples.youtube8.VideoFragment"

android:id="@+id/video_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</LinearLayout>

</merge>

No comments:

Post a Comment