Unable To Access library activity in another project
Asked Answered
S

3

0

I am trying to access library activity into another project(In tabhost and each tab call different activity.) but its throwing exception

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?

where :- com.themontcalm.droid.lib.activity.ReservationTab is a library project. And com.themontcalm.droid.activity launcher project where i am accessing library activity

code where i am accessing my project library:---

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);
        }

    }

}
Stipend answered 31/7, 2013 at 5:43 Comment(10)
have u made lib project property as "is library"? did u include ur lib project in ur main project??Transept
yes and already added in launcher projectStipend
while refering that class name it must be asking for import did u do that?Transept
yes did that and it also throwing error :- MontcalmLibs] Could not find MontcalmLibs.apk! –Stipend
do u hv source of lib project u r adding?Transept
yes i made the project and checked as library and created new project to access that library.Stipend
i m not asking that i m asking is ur libaray project a apk?i mean it contains class files or its source is avaialbe?Transept
check the post i have edited with the code where i am accessing that libraryStipend
library project have some activityStipend
thanks for help .... i placed all activity declaration in launcher project manifest file and its working –Stipend
T
2

I doubt that <activity> tag declaration in manifest file will work but give a try and do include this in manifest file:

<uses-library android:name="com.themontcalm.droid.lib.activityr"
android:required="true" /> 
Transept answered 31/7, 2013 at 6:8 Comment(2)
declare ur activity in ur main project with its package nameTransept
i did that and its working i placed all activity declaration in launcher project manifest file and its working... i wonder why....Stipend
P
0

You should declare your com.themontcalm.droid.lib.activity.ReservationTab library in your current project. To do this,

  1. go to properties and then Android, below there is Library part, click to add button and select your library.
  2. That was it before eclipse get updated, but now you should also go Java Built Path and select your library.
Pitchdark answered 31/7, 2013 at 5:49 Comment(7)
i did those process... and it also throwing error :- MontcalmLibs] Could not find MontcalmLibs.apk!Stipend
i have cleaned my launcher project and library project several times it does not helped me...Stipend
Finally, whould you mind to share the code snipped how you call that class in your launcher project?Pitchdark
check the post i have edited with the code where i am accessing that libraryStipend
Ok, with this code intent = new Intent().setClass(getBaseContext(), com.themontcalm.droid.lib.activity.ReservationTab.class); you only declare its class, you may need to set its package as well.Pitchdark
Can you try to call that activity like this: Intent intent = new Intent("com.themontcalm.droid.lib.activity.ReservationTab"); intent.setClassName("com.themontcalm.droid.activity", "com.themontcalm.droid.lib.activity.ReservationTab");Pitchdark
thanks for help .... i placed all activity declaration in launcher project manifest file and its workingStipend
G
0

Ensure you are linking the library projects as a library rather than external jar. go to Project properties > Android > Library, then click add library.

Then as you are doing define the activity in your project manifest

<activity
        android:label="@string/app_name"
        android:name="fullpath.LibraryProjectActivity" >    
</activity>
Gauger answered 31/7, 2013 at 5:56 Comment(2)
may i have to define library activity in launcher project where i am accessing itStipend
yes u have to add in the manifest file of the launcher project tooGauger

© 2022 - 2024 — McMap. All rights reserved.