0

我正在尝试从一个选项卡活动中单击时启动新的选项卡活动

我能够将这些东西加载到第一个活动onclick中......但是照片按钮如其中一个类中所示,出现错误,如日志猫中所示......

我该如何解决这个问题

有任何想法吗

AndroidTabRestaurantDescListView.java

public class AndroidTabRestaurantDescListView extends TabActivity {

    // TabSpec Names
        private static final String INBOX_SPEC = "Rating";
        private static final String OUTBOX_SPEC = "Price";
        private static final String PROFILE_SPEC = "Distance";

        Button Photos;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            Photos=(Button) findViewById(R.id.PhotoButton); 

            TabHost tabHost = getTabHost();

            // Inbox Tab
            TabSpec inboxSpec = tabHost.newTabSpec(INBOX_SPEC);
            Intent inboxIntent = new Intent(this, MainActivity.class);
            inboxSpec.setIndicator(INBOX_SPEC);
            // Tab Content
            inboxSpec.setContent(inboxIntent);

            // Outbox Tab
            TabSpec PriceSpec = tabHost.newTabSpec(OUTBOX_SPEC);
            Intent PriceIntent = new Intent(this, PriceDescriptionActivity.class);
            PriceSpec .setIndicator(OUTBOX_SPEC);
            PriceSpec.setContent(PriceIntent);

            // Profile Tab
            TabSpec DistanceSpec = tabHost.newTabSpec(PROFILE_SPEC);
            Intent DistanceIntent = new Intent(this, DistanceDiscriptionActivity.class);
            DistanceSpec .setIndicator(PROFILE_SPEC); 
            DistanceSpec.setContent(DistanceIntent);

            // Adding all TabSpec to TabHost
            tabHost.addTab(inboxSpec); 
            tabHost.addTab(PriceSpec); 
            tabHost.addTab(DistanceSpec); 

            //Set the current value tab to default first tab
            tabHost.setCurrentTab(0);

            //Setting custom height for the tabs
            final int height = 45;
            tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
            tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;
            tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = height;




            Photos.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    Intent PhotoIntent=new Intent(AndroidTabRestaurantDescListView.this,AndroidTabRestaurantDescImageListView.class);
                    startActivity(PhotoIntent);

                }
            });

        }

}

显现

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.androidbegin.jsonparsetutorial"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity android:name="com.project.findmybuffet.AndroidTabRestaurantDescListView" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.project.findmybuffet.SingleItemView" >
        </activity>


        <activity
            android:name="com.project.findmybuffet.RestaurantDesc"
            android:label="@string/app_name" >
        </activity>

        <activity
            android:name="com.project.findmybuffet.RestaurantPhotos"
            android:label="@string/app_name" >
        </activity>


        <activity
            android:name="com.project.findmybuffet.DistanceDiscriptionActivity">
        </activity>    

        <activity
            android:name="com.project.findmybuffet.PriceDescriptionActivity">
        </activity> 

        <activity
            android:name="com.project.findmybuffet.MainActivity">
        </activity> 

        <activity
            android:name="com.project.findmybuffet.AndroidTabRestaurantDescImageListView">
        </activity> 

        <activity
            android:name="com.project.findmybuffet.DistanceDiscriptionOnlyImageActivity">
        </activity> 

        <activity
            android:name="com.project.findmybuffet.PriceDescriptionOnlyImageActivity">
        </activity> 

    </application>

</manifest>

日志::

09-28 12:12:40.415: I/MemoryCache(1222): MemoryCache will use up to 8.0MB
09-28 12:12:40.875: D/dalvikvm(1222): GC_EXTERNAL_ALLOC freed 313K, 50% free 2967K/5895K, external 2130K/2137K, paused 119ms
09-28 12:12:40.925: I/MemoryCache(1222): cache size=47000 length=1
09-28 12:12:41.105: I/MemoryCache(1222): cache size=111500 length=2
09-28 12:12:41.245: I/MemoryCache(1222): cache size=179940 length=3
09-28 12:12:41.285: I/MemoryCache(1222): cache size=237060 length=4
09-28 12:12:48.255: D/AndroidRuntime(1222): Shutting down VM
09-28 12:12:48.255: W/dalvikvm(1222): threadid=1: thread exiting with uncaught exception (group=0x40015560)
09-28 12:12:48.287: E/AndroidRuntime(1222): FATAL EXCEPTION: main
09-28 12:12:48.287: E/AndroidRuntime(1222): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidbegin.jsonparsetutorial/com.project.findmybuffet.AndroidTabRestaurantDescImageListView}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidbegin.jsonparsetutorial/com.project.findmybuffet.RatingDescriptionOnlyImageActivity}; have you declared this activity in your AndroidManifest.xml?
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.os.Looper.loop(Looper.java:123)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.app.ActivityThread.main(ActivityThread.java:3683)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at java.lang.reflect.Method.invokeNative(Native Method)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at java.lang.reflect.Method.invoke(Method.java:507)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at dalvik.system.NativeStart.main(Native Method)
09-28 12:12:48.287: E/AndroidRuntime(1222): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidbegin.jsonparsetutorial/com.project.findmybuffet.RatingDescriptionOnlyImageActivity}; have you declared this activity in your AndroidManifest.xml?
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.app.ActivityThread.resolveActivityInfo(ActivityThread.java:1457)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:277)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.widget.TabHost.setCurrentTab(TabHost.java:326)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.widget.TabHost.addTab(TabHost.java:216)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at com.project.findmybuffet.AndroidTabRestaurantDescImageListView.onCreate(AndroidTabRestaurantDescImageListView.java:44)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-28 12:12:48.287: E/AndroidRuntime(1222):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-28 12:12:48.287: E/AndroidRuntime(1222):     ... 11 more
4

2 回答 2

1

错误消息非常具有描述性:

找不到显式活动类 {com.androidbegin.jsonparsetutorial/com.project.findmybuffet.RatingDescriptionOnlyImageActivity};您是否在 AndroidManifest.xml 中声明了此活动?

答案是:不,您还没有在清单中声明该活动。您的清单中有很多其他活动,但不是那个。

除了通过将活动添加到清单中来简单地解决此问题外,我建议您退后一步,考虑如何自己解决这个问题。您是否仔细阅读了日志文件?您是否以某种方式错过了我引用的错误消息?(始终寻找“原因”异常消息。)学习如何为自己诊断问题非常重要——所以看看你是否能弄清楚为什么这次你没有做到这一点,以便下次改进。

于 2013-09-28T06:51:13.980 回答
0

发生此错误是因为您尚未在清单中声明 RatingDescriptionOnlyImageActivity 此活动。您已声明所有其他活动,但未声明此活动。因此,请查看清单文件并正确检查包名称,然后将此活动写入您的清单文件。你的问题肯定会得到解决。

于 2013-09-28T07:17:43.910 回答