how to use an external jar - android

I read a lot about this issue but I still can´t do it work.
I have two projects: one does some stuff and what I want to do is set it as jar file and use it in the main project, call it and take the info I don´t know how to instanciate a class of that package to start with the process. The secondary project works fine alone and I want to take the info and use it in the main project. If I set the secondary as Library and add it to the main it works fine but I don´t want to do it in this way.
I think it´s possible to do it but I don´t know how to instantiate a class from a jar file and I´m starting to be desperate.
this is the logCat when I call the activity in the jared
file 03-22 11:04:57.900: E/AndroidRuntime(11895): FATAL EXCEPTION: main
03-22 11:04:57.900: E/AndroidRuntime(11895): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.suscribir/com.example.suscribir.Suscribir}; have you declared this activity in your AndroidManifest.xml?
03-22 11:04:57.900: E/AndroidRuntime(11895): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-22 11:04:57.900: E/AndroidRuntime(11895): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-22 11:04:57.900: E/AndroidRuntime(11895): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-22 11:04:57.900: E/AndroidRuntime(11895): at android.app.Activity.startActivity(Activity.java:2933)
03-22 11:04:57.900: E/AndroidRuntime(11895): at com.example.principal.Principal$1.onClick(Principal.java:37)
03-22 11:04:57.900: E/AndroidRuntime(11895): at android.view.View.performClick(View.java:2485)
03-22 11:04:57.900: E/AndroidRuntime(11895): at android.view.View$PerformClick.run(View.java:9080)
03-22 11:04:57.900: E/AndroidRuntime(11895): at android.os.Handler.handleCallback(Handler.java:587)
03-22 11:04:57.900: E/AndroidRuntime(11895): at android.os.Handler.dispatchMessage(Handler.java:92)
03-22 11:04:57.900: E/AndroidRuntime(11895): at android.os.Looper.loop(Looper.java:130)
03-22 11:04:57.900: E/AndroidRuntime(11895): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-22 11:04:57.900: E/AndroidRuntime(11895): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 11:04:57.900: E/AndroidRuntime(11895): at java.lang.reflect.Method.invoke(Method.java:507)
03-22 11:04:57.900: E/AndroidRuntime(11895): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
03-22 11:04:57.900: E/AndroidRuntime(11895): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
03-22 11:04:57.900: E/AndroidRuntime(11895): at dalvik.system.NativeStart.main(Native Method)
this is how I call the Activity with an intent
intent.setAction(Intent.ACTION_MAIN);
intent.setClassName("com.example.suscribir", "com.example.suscribir.Suscribir");
startActivity(intent);
this is the Manifest
<activity
android:name="com.example.suscribir.Suscribir">
</activity>
If you need more info, just tell me
Thanks again

http://androiddevelopement.blogspot.in/2011/01/creating-jar-file-in-eclipse.html.
Creating jar from eclipse
Cannot package resources, manifest entries. Pure Java code (perhaps using Android APIs), can be packaged into jars.
To use it , just copy the jar to your libs folder under the project.
Right click on project. Goto Properties. Java Build Path. Click Add Jars. Add jar from your libs folder.
After that you can use import statement and instantiate it in your new project class.

I'm not completely sure if I understand your question right. You have two Android applications that use the same classes? Is that right? You need to extract the common classes into a Library project in that case. I don't think that you can reference one Android Application project from another.

Finally, I found a way to use a project into another as library. This tuto is in Spanish byt is really easy following the images in each step
http://es.slideshare.net/ajdgeniz/como-hacer-un-archivo-jar-en-eclipse

Related

android application stopped unexpectedly emulator

Couldn't able to find the error. Logcat Provided
03-22 00:08:15.677: E/dalvikvm(275): Could not find class 'net.sourceforge.jeval.Evaluator', referenced from method com.math.Mainactivitycalculator.onCreate
03-22 00:08:15.927: E/AndroidRuntime(275): FATAL EXCEPTION: main
03-22 00:08:15.927: E/AndroidRuntime(275): java.lang.NoClassDefFoundError: net.sourceforge.jeval.Evaluator
03-22 00:08:15.927: E/AndroidRuntime(275): at com.dbl.dothemath.Mainactivitycalculator.onCreate(Mainactivitycalculator.java:76)
03-22 00:08:15.927: E/AndroidRuntime(275): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-22 00:08:15.927: E/AndroidRuntime(275): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-22 00:08:15.927: E/AndroidRuntime(275): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-22 00:08:15.927: E/AndroidRuntime(275): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-22 00:08:15.927: E/AndroidRuntime(275): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-22 00:08:15.927: E/AndroidRuntime(275): at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 00:08:15.927: E/AndroidRuntime(275): at android.os.Looper.loop(Looper.java:123)
03-22 00:08:15.927: E/AndroidRuntime(275): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-22 00:08:15.927: E/AndroidRuntime(275): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 00:08:15.927: E/AndroidRuntime(275): at java.lang.reflect.Method.invoke(Method.java:521)
03-22 00:08:15.927: E/AndroidRuntime(275): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-22 00:08:15.927: E/AndroidRuntime(275): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-22 00:08:15.927: E/AndroidRuntime(275): at dalvik.system.NativeStart.main(Native Method)
mathematical Expression involving numbers.
Numbers are treated as doubles, so resulting numbers will contain at least one decimal place.
string String can also be added together, compared, etc...
Boolean Expression that evaluate to true (1.0) and false (0.0).
functional Custom functions can be created or there are many Math and String functions that JEval supplies with this class.

GCM issues on the android client

I have an android app that was working previously, I had to set up the dev environment on a new PC. Everything compiles fine (i'm using Android Studio), but I get the following error:
11-26 15:25:22.737 15132-15132/com.sample E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gcm.GCMRegistrar
at com.sample.views.loginregistration.LoginManager.handleRegistration(LoginManager.java:147)
at com.sample.views.loginregistration.LoginViewFragment.onCreateView(LoginViewFragment.java:74)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:871)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:523)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5143)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
It's saying it cannot find gcm.jar which is clearly in the project and in a folder called libs. These were the common issues that people reported in other SO posts. The app basically launches and then crashes on the spot... But i'm confused as the setup is correct.
Is there anything else that could be wrong with this?
It might be a build.gradle issue. You should have this in your build.gradle file
dependencies {
compile files('libs/gcm.jar')
}
Once you've added that, go to Tools -> Android -> Sync Project with Gradle Files

java.lang.VeriryError encountered

Deat developers.
I have made an application but i encounter the following problem:
Occasionally (not always - some times) i get the following error:
java.lang.VerifyError: com/google/example/games/basegameutils/GameHelper
at com.google.example.games.basegameutils.BaseGameActivity.onCreate(BaseGameActivity.java:103)
at development.nk.games.tanc.MainActivity.onCreate(MainActivity.java:97)
at android.app.Activity.performCreate(Activity.java:5047)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
at android.app.ActivityThread.access$700(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
I have looked after this problem and i read that i have to check all Libraries. I did that but the problem still is there.
The class "GameHelper" is a helper class that i use from google play services.
"MainActivity" is the main Activity my app runs. "MainActivity" extends "BaseGameActivity" which uses the "GameHelper" class.
Thank you in advance.

App crashes when trying to extend SherlockActivity in android studio

After importing the actionbarsherlock module, my app crashes on any activity that extends the SherlockActivity. I am not sure if I had imported it incorrectly or something needs to be adjusted but I have followed a guide that was previously posted here on stackoverflow. If i extend Activity and not sherlockActivity there will be no crash.
Guide https://stackoverflow.com/a/16591272/1671933
Logcat
05-24 08:41:46.072 1241-1241/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.example.sandbox.TestingCam
at com.example.sandbox.LoginActivity$CheckLogin.onPostExecute(LoginActivity.java:204)
at com.example.sandbox.LoginActivity$CheckLogin.onPostExecute(LoginActivity.java:155)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
You need to make sure that the dependency scope is set to "compile". In some cases it seem to be set to "provided" which will cause a NoClassDefFoundError.

Android onDestroy Error

In my app there is one activity I have where I call onDestroy and inside it I have the following:
#Override
public void onDestroy()
{
productAdapter.imageLoader.stopThread();
lvProducts.setAdapter(null);
super.onDestroy();
}
productAdapter is my ListView adapter and I am using the fedorvlasov lazy load functionality.
The issue is, when I leave the app for a LONG time and come back, I try to access this activity from the main activity and I get the following:
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): FATAL EXCEPTION: main
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): java.lang.RuntimeException: Unable to destroy activity {com.MyApp/com.MyApp.Products}: java.lang.NullPointerException
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3081)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3146)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at android.app.ActivityThread.access$2100(ActivityThread.java:132)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1071)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at android.os.Looper.loop(Looper.java:150)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at android.app.ActivityThread.main(ActivityThread.java:4263)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at java.lang.reflect.Method.invoke(Method.java:507)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at dalvik.system.NativeStart.main(Native Method)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): Caused by: java.lang.NullPointerException
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at com.MyApp.Productss.onDestroy(DailyDeals.java:678)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3063)
The thing is, I dont know how to reproduce this because it only happens if I leave the app for a long time and come back. Its almost like there is an Android timeout that says after this many hours, cause app to start over.
The system will kill your application whenever it needs the resources to use for something else. This is why when you come back after a long time it is no longer running.
why do you have this line?
lvProducts.setAdapter(null);
I think that is what is giving you a null pointer. It isn't liking that you are trying to set it with a null adapter. Try removing this line
Also just to be sure, which line is 678?

Categories

Resources