Reputation: 1772
I'm trying to start an Activity from an application that resides in an android library. I keep getting the following exception when I try to start the activity from application.
09-07 12:26:35.300: E/AndroidRuntime(553): FATAL EXCEPTION: main
09-07 12:26:35.300: E/AndroidRuntime(553): java.lang.IllegalStateException: Could not execute method of the activity
09-07 12:26:35.300: E/AndroidRuntime(553): at android.view.View$1.onClick(View.java:3044)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.view.View.performClick(View.java:3511)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.view.View$PerformClick.run(View.java:14105)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.os.Handler.handleCallback(Handler.java:605)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.os.Handler.dispatchMessage(Handler.java:92)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.os.Looper.loop(Looper.java:137)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-07 12:26:35.300: E/AndroidRuntime(553): at java.lang.reflect.Method.invokeNative(Native Method)
09-07 12:26:35.300: E/AndroidRuntime(553): at java.lang.reflect.Method.invoke(Method.java:511)
09-07 12:26:35.300: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-07 12:26:35.300: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-07 12:26:35.300: E/AndroidRuntime(553): at dalvik.system.NativeStart.main(Native Method)
09-07 12:26:35.300: E/AndroidRuntime(553): Caused by: java.lang.reflect.InvocationTargetException
09-07 12:26:35.300: E/AndroidRuntime(553): at java.lang.reflect.Method.invokeNative(Native Method)
09-07 12:26:35.300: E/AndroidRuntime(553): at java.lang.reflect.Method.invoke(Method.java:511)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.view.View$1.onClick(View.java:3039)
09-07 12:26:35.300: E/AndroidRuntime(553): ... 11 more
09-07 12:26:35.300: E/AndroidRuntime(553): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.smarttech.androidlibrary.LibraryActivity.LAUNCH }
09-07 12:26:35.300: E/AndroidRuntime(553): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.app.Activity.startActivityForResult(Activity.java:3190)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.app.Activity.startActivity(Activity.java:3297)
09-07 12:26:35.300: E/AndroidRuntime(553): at com.smarttech.application.MainActivity.buttonLaunchActivity(MainActivity.java:25)
09-07 12:26:35.300: E/AndroidRuntime(553): ... 14 more
I'm working in Eclipse, and I have created two projects - application and library.
Library is declared as an Android Library through Properties->Android->Is Library
Application references the library through Properties->Android->Add.
I followed the instructions for Managing Projects from Eclipse with ADT.
LIBRARY:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smarttech.androidlibrary"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".LibraryActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="com.smarttech.androidlibrary.LibraryActivity.LAUNCH" />
</intent-filter>
</activity>
</application>
</manifest>
APPLICATION:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smarttech.application"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.smarttech.androidlibrary.LibraryActivity">
<intent-filter>
<action android:name="com.smarttech.androidlibrary.LibraryActivity.LAUNCH"/>
</intent-filter>
</activity>
</application>
</manifest>
--
package com.smarttech.application;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void buttonLaunchActivity(View view) {
Intent i = new Intent("com.smarttech.androidlibrary.LibraryActivity.LAUNCH");
startActivity(i);
}
}
Upvotes: 2
Views: 2269
Reputation: 5643
This should work
public void buttonLaunchActivity(View view) {
Intent i = new Intent(this, LibraryActivity.class);
startActivity(i);
}
Upvotes: 2
Reputation: 36302
You still need to register the intent filter for the activity in your application manifest. Add that in and it should work:
<activity
android:name="com.smarttech.androidlibrary.LibraryActivity"
android:label="@string/title_activity_main">
<intent-filter>
<action android:name="com.smarttech.androidlibrary.LibraryActivity.LAUNCH" />
</intent-filter>
</activity>
Upvotes: 0