Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, NoSuchFieldError when launching second activity

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

like image 879
drt Avatar asked Dec 19 '11 16:12

drt


1 Answers

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?)

like image 124
josephus Avatar answered Nov 08 '22 08:11

josephus