1

I have this scenario: I have a main project that has a jar file (a secondary project that gives some info to the main one). I created the jar file followin this tuto and then add the jar file to the main project in /libs and then add it in the Build Path.

When I call the activity from the jar file there is a Fatal Exception

This is the logCat

03-22 12:47:09.509: D/AndroidRuntime(13341): Shutting down VM
03-22 12:47:09.509: W/dalvikvm(13341): threadid=1: thread exiting with uncaught exception (group=0x40018578)
03-22 12:47:09.529: E/AndroidRuntime(13341): FATAL EXCEPTION: main
03-22 12:47:09.529: E/AndroidRuntime(13341): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.XXX.YYY/com.XXX.YYY.Subscription}; have you declared this activity in your AndroidManifest.xml?
03-22 12:47:09.529: E/AndroidRuntime(13341):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at android.app.Activity.startActivityForResult(Activity.java:2827)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at com.example.principal.Principal$1.onClick(Principal.java:40)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at android.view.View.performClick(View.java:2485)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at android.view.View$PerformClick.run(View.java:9080)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at android.os.Handler.handleCallback(Handler.java:587)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at android.os.Looper.loop(Looper.java:130)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at android.app.ActivityThread.main(ActivityThread.java:3687)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at java.lang.reflect.Method.invokeNative(Native Method)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at java.lang.reflect.Method.invoke(Method.java:507)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
03-22 12:47:09.529: E/AndroidRuntime(13341):    at dalvik.system.NativeStart.main(Native Method)

This is how I call the activity in the main project

final Intent intent = new Intent();
        
        Button juego1Btn = (Button) findViewById(R.id.juego1Btn);
        
        juego1Btn.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                /*Intent intent = new Intent(getBaseContext(), Subscription.class);
                startActivity(intent);*/
                intent.setAction(Intent.ACTION_MAIN);
                intent.setClassName("com.XXX.YYY", "com.XXX.YYY.Subscription");
                intent.putExtra("code", codigo);
                intent.putExtra("keyword", keyword);
                startActivityForResult(intent, 1);
            }
        });

and this is the manifest

<activity
            android:name="com.XXX.YYY.Subscription"
            android:label="@string/app_name">
</activity>

Any idea about why I have that Exception??

Thank you very much!!!

Community
  • 1
  • 1
Ivan
  • 215
  • 3
  • 17

2 Answers2

1

First, com.XXX.YYY.Subscription would need to be com.telecoming.sms_payment.Subscription, if your code is to believed.

Second, do not create your Intent that way, as your <activity> does not claim to support ACTION_MAIN. Replace your code with:

    Button juego1Btn = (Button) findViewById(R.id.juego1Btn);

    juego1Btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(WhateverYourActivityClassIsWhereYouAreRightNow.this, Subscription.class);
            intent.putExtra("code", codigo);
            intent.putExtra("keyword", keyword);
            startActivityForResult(intent, 1);
        }
    });

(replacing WhateverYourActivityClassIsWhereYouAreRightNow with the name of the Activity that this code resides in)

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks CoomnsWare, I did as you said but Subscription.class can not be resolved as a type. I also imported the package in the main activity import com.telecoming.sms_payment.*; – Ivan Mar 22 '13 at 11:59
  • @Ivan: Then you do not have a class named `com.telecoming.sms_payment.Subscription`, apparently. This is specifically why you should use the `Intent` constructor that I recommended, so you get compile-time errors. Either you need to implement this class, or you need to read the `package` statement at the top of the `Subscription` class file to learn what the right package name is. – CommonsWare Mar 22 '13 at 12:00
  • com.telecoming.sms_payment.Subscription is the name of te activity in the jar file, do I need to implement the class if I call the method with the intent?? if yes how do I do it?? – Ivan Mar 22 '13 at 12:04
  • @Ivan: "com.telecoming.sms_payment.Subscription is the name of te activity in the jar file" -- then the JAR file is not in `libs/`, or you messed up your build path manually. – CommonsWare Mar 22 '13 at 12:05
  • Yeah the JAR is in libs and this is a huge mess CommonsWare... I have a jar file wich checks if a person is suscripted, I jared it to be used in different applications. In the new project I put jar file in libs and then added it as a Jar in Build Path. Now I don´t know how to take the info the jar file gives when I call it. Maybe I didn´t present the problem properly – Ivan Mar 22 '13 at 12:11
  • @Ivan: If you are able to reference other classes out of that JAR, then your belief that `com.telecoming.sms_payment.Subscription` is in the JAR is incorrect. If you are unable to reference anything out of the JAR, then your project's build path is presumably broken, somehow. – CommonsWare Mar 22 '13 at 12:15
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/26723/discussion-between-ivan-and-commonsware) – Ivan Mar 22 '13 at 12:19
0

The problem was in the way I created the library, via following this tuto step by step it works fine http://es.slideshare.net/ajdgeniz/como-hacer-un-archivo-jar-en-eclipse

Thanks everybody

Ivan
  • 215
  • 3
  • 17