0

到目前为止,这个应用程序的唯一任务是在我水平滑动屏幕时滑动。但是当我在我的 Android 虚拟机上运行它时,logcat 会弹出这些错误:

04-14 16:14:17.822: D/ddm-heap(196): Got feature list request
04-14 16:14:18.193: D/AndroidRuntime(196): Shutting down VM
04-14 16:14:18.193: W/dalvikvm(196): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-14 16:14:18.193: E/AndroidRuntime(196): Uncaught handler: thread main exiting due to uncaught exception
04-14 16:14:18.313: E/AndroidRuntime(196): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{stc1.hello.here/stc1.hello.here.Stc1Activity}: java.lang.ClassNotFoundException: stc1.hello.here.Stc1Activity in loader dalvik.system.PathClassLoader@44c067e8
04-14 16:14:18.313: E/AndroidRuntime(196):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
04-14 16:14:18.313: E/AndroidRuntime(196):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-14 16:14:18.313: E/AndroidRuntime(196):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-14 16:14:18.313: E/AndroidRuntime(196):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-14 16:14:18.313: E/AndroidRuntime(196):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-14 16:14:18.313: E/AndroidRuntime(196):  at android.os.Looper.loop(Looper.java:123)
04-14 16:14:18.313: E/AndroidRuntime(196):  at android.app.ActivityThread.main(ActivityThread.java:4363)
04-14 16:14:18.313: E/AndroidRuntime(196):  at java.lang.reflect.Method.invokeNative(Native Method)
04-14 16:14:18.313: E/AndroidRuntime(196):  at java.lang.reflect.Method.invoke(Method.java:521)
04-14 16:14:18.313: E/AndroidRuntime(196):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-14 16:14:18.313: E/AndroidRuntime(196):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-14 16:14:18.313: E/AndroidRuntime(196):  at dalvik.system.NativeStart.main(Native Method)
04-14 16:14:18.313: E/AndroidRuntime(196): Caused by: java.lang.ClassNotFoundException: stc1.hello.here.Stc1Activity in loader dalvik.system.PathClassLoader@44c067e8
04-14 16:14:18.313: E/AndroidRuntime(196):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-14 16:14:18.313: E/AndroidRuntime(196):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-14 16:14:18.313: E/AndroidRuntime(196):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-14 16:14:18.313: E/AndroidRuntime(196):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-14 16:14:18.313: E/AndroidRuntime(196):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
04-14 16:14:18.313: E/AndroidRuntime(196):  ... 11 more
04-14 16:14:18.403: I/dalvikvm(196): threadid=7: reacting to signal 3
04-14 16:14:18.413: E/dalvikvm(196): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
04-14 16:14:35.972: D/AndroidRuntime(228): Shutting down VM
04-14 16:14:36.052: W/dalvikvm(228): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-14 16:14:36.052: E/AndroidRuntime(228): Uncaught handler: thread main exiting due to uncaught exception
04-14 16:14:36.112: E/AndroidRuntime(228): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{stc1.hello.here/stc1.hello.here.Stc1Activity}: java.lang.ClassNotFoundException: stc1.hello.here.Stc1Activity in loader dalvik.system.PathClassLoader@44e8c7e8
04-14 16:14:36.112: E/AndroidRuntime(228):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
04-14 16:14:36.112: E/AndroidRuntime(228):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-14 16:14:36.112: E/AndroidRuntime(228):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-14 16:14:36.112: E/AndroidRuntime(228):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-14 16:14:36.112: E/AndroidRuntime(228):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-14 16:14:36.112: E/AndroidRuntime(228):  at android.os.Looper.loop(Looper.java:123)
04-14 16:14:36.112: E/AndroidRuntime(228):  at android.app.ActivityThread.main(ActivityThread.java:4363)
04-14 16:14:36.112: E/AndroidRuntime(228):  at java.lang.reflect.Method.invokeNative(Native Method)
04-14 16:14:36.112: E/AndroidRuntime(228):  at java.lang.reflect.Method.invoke(Method.java:521)
04-14 16:14:36.112: E/AndroidRuntime(228):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-14 16:14:36.112: E/AndroidRuntime(228):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-14 16:14:36.112: E/AndroidRuntime(228):  at dalvik.system.NativeStart.main(Native Method)
04-14 16:14:36.112: E/AndroidRuntime(228): Caused by: java.lang.ClassNotFoundException: stc1.hello.here.Stc1Activity in loader dalvik.system.PathClassLoader@44e8c7e8
04-14 16:14:36.112: E/AndroidRuntime(228):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-14 16:14:36.112: E/AndroidRuntime(228):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-14 16:14:36.112: E/AndroidRuntime(228):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-14 16:14:36.112: E/AndroidRuntime(228):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-14 16:14:36.112: E/AndroidRuntime(228):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
04-14 16:14:36.112: E/AndroidRuntime(228):  ... 11 more
04-14 16:14:36.174: I/dalvikvm(228): threadid=7: reacting to signal 3
04-14 16:14:36.174: E/dalvikvm(228): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

这是 FragmentActivity.java:

package stc1.hello.here;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

public class FragmentActivity extends Activity {
    //We declare how many pages we want here.
    private ViewPager awesomePager;
    private static int NUM_AWESOME_VIEWS = 20;
    private Context cxt;
    private AwesomePagerAdapter awesomeAdapter;

    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main1);
        cxt = this;

        awesomeAdapter = new AwesomePagerAdapter();
        awesomePager = (ViewPager) findViewById(R.layout.main1);
        awesomePager.setAdapter(awesomeAdapter);
    }

    private class AwesomePagerAdapter extends PagerAdapter{

        @Override
        public int getCount() {
            return NUM_AWESOME_VIEWS;
        }

        /**
         * Create the page for the given position.  The adapter is responsible
         * for adding the view to the container given here, although it only
         * must ensure this is done by the time it returns from
         * {@link #finishUpdate()}.
         *
         * @param container The containing View in which the page will be shown.
         * @param position The page position to be instantiated.
         * @return Returns an Object representing the new page.  This does not
         * need to be a View, but can be some other container of the page.
         */
        @Override
        public Object instantiateItem(View collection, int position) {
            TextView tv = new TextView(cxt);
            tv.setText("Bonjour PAUG " + position);
            tv.setTextColor(Color.WHITE);
            tv.setTextSize(30);
            ((ViewPager) collection).addView(tv,0);
            return tv;
        }

        /**
         * Remove a page for the given position.  The adapter is responsible
         * for removing the view from its container, although it only must ensure
         * this is done by the time it returns from {@link #finishUpdate()}.
         *
         * @param container The containing View from which the page will be removed.
         * @param position The page position to be removed.
         * @param object The same object that was returned by
         * {@link #instantiateItem(View, int)}.
         */
        @Override
        public void destroyItem(View collection, int position, Object view) {
            ((ViewPager) collection).removeView((TextView) view);
        }

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

        /**
         * Called when the a change in the shown pages has been completed.  At this
         * point you must ensure that all of the pages have actually been added or
         * removed from the container as appropriate.
         * @param container The containing View which is displaying this adapter's
         * page views.
         */
        @Override
        public void finishUpdate(View arg0) {}


        @Override
        public void restoreState(Parcelable arg0, ClassLoader arg1) {}

        @Override
        public Parcelable saveState() {
            return null;
        }

        @Override
        public void startUpdate(View arg0) {}
    }
}

这是main1.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  >
  <android.support.v4.view.ViewPager
    android:id="@+android:id/viewpager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />
</LinearLayout>
4

1 回答 1

0

您的活动名称与错误中给出的活动名称不匹配:

Caused by: java.lang.ClassNotFoundException: stc1.hello.here.Stc1Activity

您可能需要使用正确的名称更新清单。

于 2012-04-16T15:19:47.200 回答