0

我正在尝试将库活动访问到另一个项目中(在 tabhost 中,每个选项卡调用不同的活动。)但它抛出异常

Caused by: android.content.ActivityNotFoundException: Unable to find
explicit activity class
{com.themontcalm.droid.activity/com.themontcalm.droid.lib.activity.ReservationTab};
have you declared this activity in your AndroidManifest.xml?

其中 :- com.themontcalm.droid.lib.activity.ReservationTab是一个图书馆项目。以及com.themontcalm.droid.activity我正在访问图书馆活动的启动器项目

我正在访问我的项目库的代码:---

package com.themontcalm.droid.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TabHost;


public class HomeScreen extends TabActivity implements OnClickListener {
    TabHost tabHost;
    ImageButton location, contacts, explore;
    Intent intent;
    //LocationGB locationActivity = new LocationGB();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_screen);
    //LocationFactory.getInstance().setLocationActivity(LocationGB.class);

        // addListenerOnButton(); 
        location = (ImageButton) findViewById(R.id.location);
        contacts = (ImageButton) findViewById(R.id.contacts);
        explore = (ImageButton) findViewById(R.id.explore);

        location.setOnClickListener(this);
        contacts.setOnClickListener(this);
        explore.setOnClickListener(this);
        Resources res = getResources(); // Resource object to get Drawables
        // The activity TabHost
        TabHost.TabSpec spec; // Reusable TabSpec for each tab
        Intent intent; // Reusable Intent for each tab

        tabHost = (TabHost) findViewById(android.R.id.tabhost);
        tabHost = getTabHost();

        // Create an Intent to launch an Activity for the tab (to be reused)

        intent = new Intent().setClass(getBaseContext(), com.themontcalm.droid.lib.activity.ReservationTab.class);
        spec = tabHost.newTabSpec("RESERVATION")
                .setIndicator("", res.getDrawable(R.drawable.testing))// ,
                                                                        // res.getDrawable(R.drawable.testing)
                .setContent(intent);

        tabHost.addTab(spec);

        // Do the same for the other tabs

        intent = new Intent().setClass(this, com.themontcalm.droid.lib.activity.GalleryTabActivity.class);
        spec = tabHost.newTabSpec("MODIFY")
                .setIndicator("", res.getDrawable(R.drawable.testing))// ,res.getDrawable(R.drawable.testing)
                .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, com.themontcalm.droid.lib.activity.VideoTabActivity.class);
        spec = tabHost.newTabSpec("VIDEO")
                .setIndicator("", res.getDrawable(R.drawable.testing))// ,
                                                                        // res.getDrawable(R.drawable.testing)
                .setContent(intent);
        tabHost.addTab(spec);

        // set tab which one you want open first time 0 or 1 or 2
        tabHost.setCurrentTab(0);

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v == location) {
    //  intent = new Intent(HomeScreen.this, LocationGB.class);
    //      HomeScreen.this.startActivity(intent);
        } else if (v == contacts) {
            intent = new Intent(HomeScreen.this, com.themontcalm.droid.lib.activity.ContactInfo.class);
            HomeScreen.this.startActivity(intent);
        } else if (v == explore) {
            intent = new Intent(HomeScreen.this, com.themontcalm.droid.lib.activity.ExplorePropertyActivity.class);
            HomeScreen.this.startActivity(intent);
        }

    }

}
4

3 回答 3

2

我怀疑<activity>清单文件中的标记声明会起作用,但请尝试将其包含在清单文件中:

<uses-library android:name="com.themontcalm.droid.lib.activityr"
android:required="true" /> 
于 2013-07-31T06:08:13.190 回答
0

您应该在当前项目中声明您的 com.themontcalm.droid.lib.activity.ReservationTab 库。去做这个,

  1. 转到属性,然后是 Android,下面是库部分,单击添加按钮并选择您的库。
  2. 那是在 eclipse 更新之前,但现在你还应该去 Java Built Path 并选择你的库。
于 2013-07-31T05:49:41.497 回答
0

确保将库项目链接为库而不是外部 jar。转到 Project properties > Android > Library,然后单击添加库。

然后在您的项目清单中定义活动

<activity
        android:label="@string/app_name"
        android:name="fullpath.LibraryProjectActivity" >    
</activity>
于 2013-07-31T05:56:44.070 回答