Refering from one android project to another Eclipse - android

I've tried this for 2 hours now and I dont seem to get it to work. I want to build a framework for my application, in another project. First of I'm just trying to reach a class from that other project. The code compiles but fails at runtime, at the line where i instantiate an object from a class from the framework.
05-24 18:04:01.645: E/dalvikvm(16927): Could not find class 'frame.test.Hello', referenced from method moduleLogin.activity.Login.loginClick
05-24 18:04:01.645: W/dalvikvm(16927): VFY: unable to resolve new-instance 190 (Lframe/test/Hello;) in LmoduleLogin/activity/Login;
05-24 18:04:02.715: W/dalvikvm(16927): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
05-24 18:04:02.720: E/AndroidRuntime(16927): at android.view.View$1.onClick(View.java:2154)
05-24 18:04:02.720: E/AndroidRuntime(16927): at android.view.View.performClick(View.java:2538)
05-24 18:04:02.720: E/AndroidRuntime(16927): at android.view.View$PerformClick.run(View.java:9152)
05-24 18:04:02.720: E/AndroidRuntime(16927): at android.os.Handler.handleCallback(Handler.java:587)
05-24 18:04:02.720: E/AndroidRuntime(16927): at android.os.Handler.dispatchMessage(Handler.java:92)
05-24 18:04:02.720: E/AndroidRuntime(16927): at android.os.Looper.loop(Looper.java:130)
05-24 18:04:02.720: E/AndroidRuntime(16927): at android.app.ActivityThread.main(ActivityThread.java:3691)
05-24 18:04:02.720: E/AndroidRuntime(16927): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 18:04:02.720: E/AndroidRuntime(16927): at java.lang.reflect.Method.invoke(Method.java:507)
05-24 18:04:02.720: E/AndroidRuntime(16927): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
05-24 18:04:02.720: E/AndroidRuntime(16927): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
05-24 18:04:02.720: E/AndroidRuntime(16927): at dalvik.system.NativeStart.main(Native Method)
05-24 18:04:02.720: E/AndroidRuntime(16927): Caused by: java.lang.reflect.InvocationTargetException
05-24 18:04:02.720: E/AndroidRuntime(16927): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 18:04:02.720: E/AndroidRuntime(16927): at java.lang.reflect.Method.invoke(Method.java:507)
05-24 18:04:02.720: E/AndroidRuntime(16927): at android.view.View$1.onClick(View.java:2149)
05-24 18:04:02.720: E/AndroidRuntime(16927): ... 11 more
05-24 18:04:02.720: E/AndroidRuntime(16927): Caused by: java.lang.NoClassDefFoundError: frame.test.Hello
05-24 18:04:02.720: E/AndroidRuntime(16927): at moduleLogin.activity.Login.loginClick(Login.java:49)
05-24 18:04:02.720: E/AndroidRuntime(16927): ... 14 more
I know there is a lot on this topic, but I've have searched for hours without any posts solving this problem. Most of the topics are how to reference to another project. But since my code is compiling it should be referenced?
And does both projects needs to be Android projects? Should the framework project be a library? Thanks for any help!

if the library project is an android project , you need to make it a library one by choosing it from the project properties , and then to reference it via the same place but on the project that uses it.
don't forget that there are some rules when you use a library project . see my post here for more information.
if the library project is java , its exactly as using other java projects.

This is a long shot, but it worked for me (having also spent hours on this, after reading all the same posts you did...)
If you are confident that you have correctly configured the project references, this could be a result of a silent build failure.
In my case, the problem arose due to incompatibilities between the build environments for my two projects. In Project "A", which was pure Java, the following line compiled without error in Project A's build environment:
if ((int) d.get("good")) == 0) {....
It turns out that this was not legal in the (Android) Project "B", which required an object cast:
if ((Integer) d.get("good")) == 0) {....
However, the only indication that I got of the error was the same as what you experienced, a "VFY: Unable to resolve..." error.
I found the error in a painful way: By copying the code from Project "A" into Project "B," finding the errors, and fixing them in Project "A." There is probably a more intelligent way than mine to find such incompatibilities, such as by tweaking the settings in both projects to match exactly.

Related

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

Having issues integrating Scandit SDK into my app

Decided to use Scandit SDK to get the barcode scanning feature in my app. Unfortunately, since I'm relatively new to Android development and Java in general I've run into a few issues that I can't seem to work out. The demo that Scandit provided doesn't give any errors(runs fine) but crashes when I try to start it up (pressing a button from one activity is meant to start it up). I've tried reading the logcat and googling a solution to the problems but I'm not getting the right solutions. Does anyone have an idea of what I'm doing wrong?
Logcat is provided below:
10-08 23:30:00.807 21563-21563/com.kwesimbia.management D/AndroidRuntime? Shutting down VM
10-08 23:30:00.807 21563-21563/com.kwesimbia.management W/dalvikvm? threadid=1: thread exiting with uncaught exception (group=0x40aa4228)
10-08 23:30:00.817 21563-21563/com.kwesimbia.management E/AndroidRuntime? FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3082)
at android.view.View.performClick(View.java:3549)
at android.view.View$PerformClick.run(View.java:14393)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4944)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3077)
at android.view.View.performClick(View.java:3549)
at android.view.View$PerformClick.run(View.java:14393)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4944)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com.kwesimbia.management.ScanditSDKDemoSimple
at com.kwesimbia.management.Activity_D.initiateCodeScan(Activity_D.java:63)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3077)
at android.view.View.performClick(View.java:3549)
at android.view.View$PerformClick.run(View.java:14393)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4944)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
10-08 23:30:00.817 32726-587/? E/EmbeddedLogger? App crashed!
Process: com.kwesimbia.management
10-08 23:30:00.817 32726-587/? E/EmbeddedLogger? App crashed!
Package: com.kwesimbia.management v1 (1.0)
10-08 23:30:00.817 32726-587/? E/EmbeddedLogger?
Application Label: firstapp
10-08 23:30:00.827 32726-587/? W/ActivityManager?
Force finishing activity com.kwesimbia.management/.Activity_D
I came across this problem as well, my solution was to extract the library files and put them as their files in the lib folder
The library basically isn't being exported with it
EDIT
So I checked out my project, basically I did these things:
In the libs folder I have a new folder called armeabi and inside that I have libscanditsdk-android-3.3.1.so
Then in my build path I have also referenced the jar file that they provide:
<classpathentry exported="true" kind="lib" path="C:/GIT/Android/FwayScannerProject/FwayScanner/libs/scanditsdk-barcodepicker-android-3.3.1.jar"/>

NoClassDefFoundError Due to Google Maps v2

I have recently had to update my SDK and ADT and since then I have been having loads of trouble with existing applications. My problem is that with one of my applications I am getting the following error:
05-24 09:13:49.234: E/AndroidRuntime(7064): FATAL EXCEPTION: main
05-24 09:13:49.234: E/AndroidRuntime(7064): java.lang.NoClassDefFoundError: com.taxi.cabfind.Map_Location
05-24 09:13:49.234: E/AndroidRuntime(7064): at com.taxi.cabfind.Pickup_Address$5.onClick(Pickup_Address.java:239)
05-24 09:13:49.234: E/AndroidRuntime(7064): at android.view.View.performClick(View.java:4204)
05-24 09:13:49.234: E/AndroidRuntime(7064): at android.view.View$PerformClick.run(View.java:17355)
05-24 09:13:49.234: E/AndroidRuntime(7064): at android.os.Handler.handleCallback(Handler.java:725)
05-24 09:13:49.234: E/AndroidRuntime(7064): at android.os.Handler.dispatchMessage(Handler.java:92)
05-24 09:13:49.234: E/AndroidRuntime(7064): at android.os.Looper.loop(Looper.java:137)
05-24 09:13:49.234: E/AndroidRuntime(7064): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-24 09:13:49.234: E/AndroidRuntime(7064): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 09:13:49.234: E/AndroidRuntime(7064): at java.lang.reflect.Method.invoke(Method.java:511)
05-24 09:13:49.234: E/AndroidRuntime(7064): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-24 09:13:49.234: E/AndroidRuntime(7064): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-24 09:13:49.234: E/AndroidRuntime(7064): at dalvik.system.NativeStart.main(Native Method)
This is occurring when I am trying to load up a fragment activity that contains maps v2.
This is confusing to me because in another application that I have, there is maps v2 code inside this app and this app has no problems with it. I have checked all the settings and made sure that everything matches, but I am still getting this crash.
Can someone please help.
EDIT
In changing the project and placing the google-play-services-lib.jar file in the libs folder I am now getting the following error
05-24 09:35:27.169: E/AndroidRuntime(11672): FATAL EXCEPTION: main
05-24 09:35:27.169: E/AndroidRuntime(11672): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
05-24 09:35:27.169: E/AndroidRuntime(11672): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
05-24 09:35:27.169: E/AndroidRuntime(11672): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-24 09:35:27.169: E/AndroidRuntime(11672): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.app.Activity.setContentView(Activity.java:1881)
05-24 09:35:27.169: E/AndroidRuntime(11672): at com.taxi.cabfind.Map_Location.onCreate(Map_Location.java:81)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.app.Activity.performCreate(Activity.java:5104)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.os.Handler.dispatchMessage(Handler.java:99)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.os.Looper.loop(Looper.java:137)
05-24 09:35:27.169: E/AndroidRuntime(11672): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-24 09:35:27.169: E/AndroidRuntime(11672): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 09:35:27.169: E/AndroidRuntime(11672): at java.lang.reflect.Method.invoke(Method.java:511)
05-24 09:35:27.169: E/AndroidRuntime(11672): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-24 09:35:27.169: E/AndroidRuntime(11672): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-24 09:35:27.169: E/AndroidRuntime(11672): at dalvik.system.NativeStart.main(Native Method)
This is now exactly the same as my other project that is working, I am really confused at why this one isn't working
You should not place the jar in libs folder.
You should google play services library project in your android project.
Import library project into workspace and eclipse.
Right click on your android project. goto properties. Choose android. click add. Browse the library project and add the same.
Now if you have updated adt to rev 22.
java.lang.ClassNotFoundException after changing nothing in the project but upgrading eclipse android sdk
to check if its a library project. right click on your google play services library goto properties choose android. You will see Is Library check box checked
After adding it looks similar to the one below
I upgrate SDK and ADT(ver22) yesterday just like you .
And have same error
I try this and it's work ...

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 Cannot access accelerometer

in my android application it does not seem to let me use the accelerometer. when i call it in a statement the application crashes. the statement that seems to be causing the crash is:
SensorManager sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
The application is simple as is only calls the accelerometer and runs when this statement is absent, the above statment is called before the onCreate method and the log cat is below
05-24 20:08:46.990: E/AndroidRuntime(1149): FATAL EXCEPTION: main
05-24 20:08:46.990: E/AndroidRuntime(1149): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.b00348312.workout/com.b00348312.workout.WorkoutAppActivity}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
05-24 20:08:46.990: E/AndroidRuntime(1149): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
05-24 20:08:46.990: E/AndroidRuntime(1149): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-24 20:08:46.990: E/AndroidRuntime(1149): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-24 20:08:46.990: E/AndroidRuntime(1149): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-24 20:08:46.990: E/AndroidRuntime(1149): at android.os.Handler.dispatchMessage(Handler.java:99)
05-24 20:08:46.990: E/AndroidRuntime(1149): at android.os.Looper.loop(Looper.java:123)
05-24 20:08:46.990: E/AndroidRuntime(1149): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-24 20:08:46.990: E/AndroidRuntime(1149): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 20:08:46.990: E/AndroidRuntime(1149): at java.lang.reflect.Method.invoke(Method.java:521)
05-24 20:08:46.990: E/AndroidRuntime(1149): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-24 20:08:46.990: E/AndroidRuntime(1149): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-24 20:08:46.990: E/AndroidRuntime(1149): at dalvik.system.NativeStart.main(Native Method)
05-24 20:08:46.990: E/AndroidRuntime(1149): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
05-24 20:08:46.990: E/AndroidRuntime(1149): at android.app.Activity.getSystemService(Activity.java:3526)
05-24 20:08:46.990: E/AndroidRuntime(1149): at com.b00348312.workout.WorkoutAppActivity.<init>(WorkoutAppActivity.java:25)
05-24 20:08:46.990: E/AndroidRuntime(1149): at java.lang.Class.newInstanceImpl(Native Method)
05-24 20:08:46.990: E/AndroidRuntime(1149): at java.lang.Class.newInstance(Class.java:1429)
05-24 20:08:46.990: E/AndroidRuntime(1149): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-24 20:08:46.990: E/AndroidRuntime(1149): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
05-24 20:08:46.990: E/AndroidRuntime(1149): ... 11 more
from the logcat i cannot figure out the cause of this problem when this statement worked in a different programme.
Thats a double negative? lol Cut the code where ure calling the system service and paste inside your onCreate
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//PLACE YOUR ACCEL CODE IN HERE
}
You have to grab the SensorManager after onCreate is called.
"System services not available to Activities before onCreate()"

Categories

Resources