不幸的是Android已经停止了错误

时间:2014-06-25 18:36:20

标签: android

我正在尝试使用ortiz extendedViewPager进行Android FullScreenActivity,但它让我遗憾地停止了错误。请提前帮助,谢谢。

FullScreenActivity.java

package com.nyt.nahw.testnahw;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.PagerAdapter;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.nyt.nahw.testnahw.util.SystemUiHider;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 * 
 * @see SystemUiHider
 */
public class FullscreenActivity extends Activity {
    /**
     * Whether or not the system UI should be auto-hidden after
     * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
     */
    private static final boolean AUTO_HIDE = true;

    /**
     * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
     * user interaction before hiding the system UI.
     */
    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

    /**
     * If set, will toggle the system UI visibility upon interaction. Otherwise,
     * will show the system UI visibility upon interaction.
     */
    private static final boolean TOGGLE_ON_CLICK = true;

    /**
     * The flags to pass to {@link SystemUiHider#getInstance}.
     */
    private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;

    /**
     * The instance of the {@link SystemUiHider} for this activity.
     */
    private SystemUiHider mSystemUiHider;

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

        setContentView(R.layout.activity_fullscreen);

        // final View contentView = findViewById(R.id.view_pager);

        ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager);
        mViewPager.setAdapter(new TouchImageAdapter());
        mViewPager.setCurrentItem(5);

        // Set up an instance of SystemUiHider to control the system UI for
        // this activity.
        mSystemUiHider = SystemUiHider.getInstance(this, mViewPager,
                HIDER_FLAGS);
        mSystemUiHider.setup();

        // Set up the user interaction to manually show or hide the system UI.
        mViewPager.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TOGGLE_ON_CLICK) {
                    mSystemUiHider.toggle();
                } else {
                    mSystemUiHider.show();
                }
            }
        });

        // Upon interacting with UI controls, delay any scheduled hide()
        // operations to prevent the jarring behavior of controls going away
        // while interacting with the UI.
        // findViewById(R.id.dummy_button).setOnTouchListener(
        // mDelayHideTouchListener);
    }

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

        // Trigger the initial hide() shortly after the activity has been
        // created, to briefly hint to the user that UI controls
        // are available.
        delayedHide(100);
    }

    /**
     * Touch listener to use for in-layout UI controls to delay hiding the
     * system UI. This is to prevent the jarring behavior of controls going away
     * while interacting with activity UI.
     */
    View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (AUTO_HIDE) {
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }
            return false;
        }
    };

    Handler mHideHandler = new Handler();
    Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            mSystemUiHider.hide();
        }
    };

    /**
     * Schedules a call to hide() in [delay] milliseconds, canceling any
     * previously scheduled calls.
     */
    private void delayedHide(int delayMillis) {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }
}

class TouchImageAdapter extends PagerAdapter {

    private static int[] images = { R.drawable.nature_1, R.drawable.nature_2,
            R.drawable.nature_3, R.drawable.nature_4, R.drawable.nature_5 };

    @Override
    public int getCount() {
        return images.length;
    }

    @Override
    public View instantiateItem(ViewGroup container, int position) {
        TouchImageView img = new TouchImageView(container.getContext());
        img.setImageResource(images[position]);
        container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        return img;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}

,XML文件如下 的 active_fullscreen.xml

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0099cc"
    tools:context="com.nyt.nahw.testnahw.FullscreenActivity" >

    <!--
         The primary full-screen view. This can be replaced with whatever view
         is needed to present your content, e.g. VideoView, SurfaceView,
         TextureView, etc.

    -->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <!-- ExtendedViewPager is a custom view and must be referred to by its full package name in XML -->

        <com.ortiz.touch.ExtendedViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>

    <!-- This FrameLayout insets its children based on system windows using android:fitsSystemWindows -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true" >

        <LinearLayout
            android:id="@+id/fullscreen_content_controls"
            style="?metaButtonBarStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/black_overlay"
            android:orientation="horizontal"
            tools:ignore="UselessParent" >

            <Button
                android:id="@+id/dummy_button"
                style="?metaButtonBarButtonStyle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/dummy_button" />
        </LinearLayout>
    </FrameLayout>

</FrameLayout>

我的LogCat在

之下
  06-25 23:25:39.898: D/AndroidRuntime(557): Shutting down VM
06-25 23:25:39.898: W/dalvikvm(557): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
06-25 23:25:39.918: E/AndroidRuntime(557): FATAL EXCEPTION: main
06-25 23:25:39.918: E/AndroidRuntime(557): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nyt.nahw.testnahw/com.nyt.nahw.testnahw.FullscreenActivity}: android.view.InflateException: Binary XML file line #19: Error inflating class com.ortiz.touch.ExtendedViewPager
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.os.Looper.loop(Looper.java:137)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.app.ActivityThread.main(ActivityThread.java:4340)
06-25 23:25:39.918: E/AndroidRuntime(557):  at java.lang.reflect.Method.invokeNative(Native Method)
06-25 23:25:39.918: E/AndroidRuntime(557):  at java.lang.reflect.Method.invoke(Method.java:511)
06-25 23:25:39.918: E/AndroidRuntime(557):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-25 23:25:39.918: E/AndroidRuntime(557):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-25 23:25:39.918: E/AndroidRuntime(557):  at dalvik.system.NativeStart.main(Native Method)
06-25 23:25:39.918: E/AndroidRuntime(557): Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class com.ortiz.touch.ExtendedViewPager
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-25 23:25:39.918: E/AndroidRuntime(557):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.app.Activity.setContentView(Activity.java:1835)
06-25 23:25:39.918: E/AndroidRuntime(557):  at com.nyt.nahw.testnahw.FullscreenActivity.onCreate(FullscreenActivity.java:53)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.app.Activity.performCreate(Activity.java:4465)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
06-25 23:25:39.918: E/AndroidRuntime(557):  ... 11 more
06-25 23:25:39.918: E/AndroidRuntime(557): Caused by: java.lang.ClassNotFoundException: com.ortiz.touch.ExtendedViewPager
06-25 23:25:39.918: E/AndroidRuntime(557):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-25 23:25:39.918: E/AndroidRuntime(557):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-25 23:25:39.918: E/AndroidRuntime(557):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.view.LayoutInflater.createView(LayoutInflater.java:552)
06-25 23:25:39.918: E/AndroidRuntime(557):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
06-25 23:25:39.918: E/AndroidRuntime(557):  ... 22 more
06-26 00:11:06.758: D/AndroidRuntime(713): Shutting down VM
06-26 00:11:06.758: W/dalvikvm(713): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
06-26 00:11:06.788: E/AndroidRuntime(713): FATAL EXCEPTION: main
06-26 00:11:06.788: E/AndroidRuntime(713): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nyt.nahw.testnahw/com.nyt.nahw.testnahw.FullscreenActivity}: android.view.InflateException: Binary XML file line #20: Error inflating class com.ortiz.touch.ExtendedViewPager
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.os.Looper.loop(Looper.java:137)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.app.ActivityThread.main(ActivityThread.java:4340)
06-26 00:11:06.788: E/AndroidRuntime(713):  at java.lang.reflect.Method.invokeNative(Native Method)
06-26 00:11:06.788: E/AndroidRuntime(713):  at java.lang.reflect.Method.invoke(Method.java:511)
06-26 00:11:06.788: E/AndroidRuntime(713):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-26 00:11:06.788: E/AndroidRuntime(713):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-26 00:11:06.788: E/AndroidRuntime(713):  at dalvik.system.NativeStart.main(Native Method)
06-26 00:11:06.788: E/AndroidRuntime(713): Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class com.ortiz.touch.ExtendedViewPager
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-26 00:11:06.788: E/AndroidRuntime(713):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.app.Activity.setContentView(Activity.java:1835)
06-26 00:11:06.788: E/AndroidRuntime(713):  at com.nyt.nahw.testnahw.FullscreenActivity.onCreate(FullscreenActivity.java:53)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.app.Activity.performCreate(Activity.java:4465)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
06-26 00:11:06.788: E/AndroidRuntime(713):  ... 11 more
06-26 00:11:06.788: E/AndroidRuntime(713): Caused by: java.lang.ClassNotFoundException: com.ortiz.touch.ExtendedViewPager
06-26 00:11:06.788: E/AndroidRuntime(713):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-26 00:11:06.788: E/AndroidRuntime(713):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-26 00:11:06.788: E/AndroidRuntime(713):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.view.LayoutInflater.createView(LayoutInflater.java:552)
06-26 00:11:06.788: E/AndroidRuntime(713):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)

2 个答案:

答案 0 :(得分:1)

感谢亲爱的回复,问题出在xml

<com.ortiz.touch.ExtendedViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

更改为

<com.nyt.nahw.ExtendedViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

它工作正常。

答案 1 :(得分:0)

引起:java.lang.ClassNotFoundException:com.ortiz.touch.ExtendedViewPager

该课程确实存在吗?你清理过你的项目吗?