【问题标题】:Unable To Access library activity in another project无法访问另一个项目中的库活动
【发布时间】:2013-07-31 05:43:03
【问题描述】:

我正在尝试将库活动访问到另一个项目中(在 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);
        }

    }

}

【问题讨论】:

  • 您是否将 lib 项目属性设置为“是库”?你是否在你的主项目中包含你的 lib 项目??
  • 是并且已经添加到启动器项目中
  • 在引用该类名时,它必须要求导入,你这样做了吗?
  • 是的,但它也抛出了错误:- MontcalmLibs] 找不到 MontcalmLibs.apk! ——
  • 你添加了 lib 项目的 hv 源吗?

标签: android android-manifest android-tabhost android-library


【解决方案1】:

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

<uses-library android:name="com.themontcalm.droid.lib.activityr"
android:required="true" /> 

【讨论】:

  • 用它的包名声明你在你的主项目中的活动
  • 我做到了,它的工作我将所有活动声明放在启动器项目清单文件中,它的工作......我想知道为什么......
【解决方案2】:

您应该在当前项目中声明您的 com.themontcalm.droid.lib.activity.ReservationTab 库。为此,

  1. 转到属性,然后是Android,下面有库部分,单击添加按钮并选择您的库。
  2. 在 eclipse 更新之前就是这样,但现在您还应该转到 Java Built Path 并选择您的库。

【讨论】:

  • 我做了这些过程......它也抛出错误:- MontcalmLibs] 找不到 MontcalmLibs.apk!
  • 我已经清理了我的启动器项目和库项目几次,但对我没有帮助...
  • 最后,您介意分享一下您在启动器项目中如何调用该类的代码吗?
  • 检查我用我正在访问该库的代码编辑的帖子
  • 好的,使用此代码 intent = new Intent().setClass(getBaseContext(), com.themontcalm.droid.lib.activity.ReservationTab.class);你只声明它的类,你可能还需要设置它的包。
【解决方案3】:

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

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

<activity
        android:label="@string/app_name"
        android:name="fullpath.LibraryProjectActivity" >    
</activity>

【讨论】:

  • 我可以在我访问它的启动器项目中定义库活动
  • 是的,你也必须在启动器项目的清单文件中添加
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-31
相关资源
最近更新 更多