9

I have two applications and am turning one into a Library so I can launch it from another application. In my library I have a facebook image and a twitter image that causes the NoSuchFieldError. I have the library defined in my manifest.

<activity android:name="com.funayman.listactivity.ApplicationListActivty" />

I am starting this activity using

startActivity(new Intent(this, ApplicationListActivty.class));

It seems to find the activity but when it launches I get the following error in LogCat:

E/AndroidRuntime(  731): java.lang.NoSuchFieldError: com.funayman.listactivity.R$id.img_fb
E/AndroidRuntime(  731):    at com.funayman.listactivity.ApplicationListActivty.onCreate(ApplicationListActivtyActivity.java:58)
E/AndroidRuntime(  731):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(  731):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
E/AndroidRuntime(  731):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime(  731):    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime(  731):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime(  731):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  731):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  731):    at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(  731):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  731):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  731):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(  731):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(  731):    at dalvik.system.NativeStart.main(Native Method)

I should point out that if I launch my Library as an application, everything works and loads correctly without any errors.

Thanks for your help!

EDIT

I found my issue. In my library I was using

setContentView(R.layout.main);

Renaming my layout solved my issue.

Thanks

drt
  • 713
  • 6
  • 9

1 Answers1

8

startActivity with new Intent(Context, class) is only applicable if your activity is within the same application. If you want to start an activity from outside of the application, use its full package name. for example,

Intent i = new Intent("com.test.application");
startActivity(i);

Also note that you have spelled Activty without an 'i' (just pointing out. maybe you deliberately did that?)

josephus
  • 8,284
  • 1
  • 37
  • 57
  • +1 for this priceless piece of information, showing up at the right place & the right time. I am sure this is hiding somewhere in my 718-page book, but yours was much easier to find. Thanks! – Bill The Ape Feb 16 '12 at 03:27