I am working on a simple android application which has a ViewPager with swiping images. I have static application containing 12 images. When I swipe, the app is getting crashed after the fourth image.
How can I understand the stacktrace and solve this problem?
e.. 05-24 21:37:25.718: E/AndroidRuntime(551): FATAL EXCEPTION: main 05-24 21:37:25.718: E/AndroidRuntime(551):
java.lang.OutOfMemoryError 05-24 21:37:25.718: E/AndroidRuntime(551):
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-24 21:37:25.718: E/AndroidRuntime(551): at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
05-24 21:37:25.718: E/AndroidRuntime(551): at
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
05-24 21:37:25.718: E/AndroidRuntime(551): at
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
05-24 21:37:25.718: E/AndroidRuntime(551): at
android.content.res.Resources.loadDrawable(Resources.java:1935) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.content.res.Resources.getDrawable(Resources.java:664) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.widget.ImageView.resolveUri(ImageView.java:542) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.widget.ImageView.setImageResource(ImageView.java:315) 05-24
21:37:25.718: E/AndroidRuntime(551): at
com.sqisland.android.swipe_image_viewer.MainActivity$ImagePagerAdapter.instantiateItem(MainActivity.java:72)
05-24 21:37:25.718: E/AndroidRuntime(551): at
android.support.v4.view.ViewPager.addNewItem(ViewPager.java:692) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.support.v4.view.ViewPager.populate(ViewPager.java:875) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.support.v4.view.ViewPager.populate(ViewPager.java:772) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.support.v4.view.ViewPager.completeScroll(ViewPager.java:1539)
05-24 21:37:25.718: E/AndroidRuntime(551): at
android.support.v4.view.ViewPager.computeScroll(ViewPager.java:1422)
05-24 21:37:25.718: E/AndroidRuntime(551): at
android.view.ViewGroup.drawChild(ViewGroup.java:2729) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.view.ViewGroup.drawChild(ViewGroup.java:2885) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.view.ViewGroup.drawChild(ViewGroup.java:2885) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.view.View.draw(View.java:10981) 05-24 21:37:25.718:
E/AndroidRuntime(551): at
android.widget.FrameLayout.draw(FrameLayout.java:450) 05-24
21:37:25.718: E/AndroidRuntime(551): at
com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2126)
05-24 21:37:25.718: E/AndroidRuntime(551): at
android.view.ViewRootImpl.draw(ViewRootImpl.java:2026) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1634)
05-24 21:37:25.718: E/AndroidRuntime(551): at
android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.os.Handler.dispatchMessage(Handler.java:99) 05-24
21:37:25.718: E/AndroidRuntime(551): at
android.os.Looper.loop(Looper.java:137) 05-24 21:37:25.718:
E/AndroidRuntime(551): at
android.app.ActivityThread.main(ActivityThread.java:4424) 05-24
21:37:25.718: E/AndroidRuntime(551): at
java.lang.reflect.Method.invokeNative(Native Method) 05-24
21:37:25.718: E/AndroidRuntime(551): at
java.lang.reflect.Method.invoke(Method.java:511) 05-24 21:37:25.718:
E/AndroidRuntime(551): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-24 21:37:25.718: E/AndroidRuntime(551): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 05-24
21:37:25.718: E/AndroidRuntime(551): at
dalvik.system.NativeStart.main(Native Method)
It seems you are using image with very large size that the device can not handle. Try using some smaller sizes
ViewPager adapter loads all your images at a time that's why you got the error. So what are the actual reason:
1. Your image size is very large
2. You did not use image resources properly. Try to put your different size image in different folder like ldpi, hdpi, xdpi folder.
Try to use the above tricks.
If you still get error, you can follow this:
Change the FragmentPagerAdapter to a FragmentStatePagerAdapter. The reason for this is that the FragmentPagerAdapter will keep all the views that it loads into memory forever. Where the FragmentStatePagerAdapter disposes of views that fall outside the current and traversable views.
Override the adapter method getItemPosition (shown below). When we call mAdapter.notifyDataSetChanged(); the ViewPager interrogates the adapter to determine what has changed in terms of positioning. We use this method to say that everything has changed so reprocess all your view positioning.
Actual answer is here: Remove Fragment Page from ViewPager in Android
I did change the FragmentPagerAdapter to a FragmentStatePagerAdapter. However the swiping motion is quite sluggish. Seems like it solved the problem for the time being.
/**
* The {#link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {#link android.support.v4.app.FragmentPagerAdapter} derivative, which
* will keep every loaded fragment in memory. If this becomes too memory
* intensive, it may be best to switch to a
* {#link android.support.v4.app.FragmentStatePagerAdapter}.
*/
The detail tutorial is available here http://blog.kerul.net/2013/09/adding-xml-layout-in-swipe-views.html
Related
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 ...
Currently project target sdk is google api level 14 and it runs well. If I changed target sdk to google api level 16 in android manifest file and run the project then it shows message unfortunately, app has stopped. Again if I change it back to level 14 then it runs.Can anyone tell me the what can be the reason?
EDIT : logcat details
05-24 10:57:09.709: E/Trace(981): error opening trace file: No such file or directory (2)
05-24 10:57:11.108: E/AndroidRuntime(981): FATAL EXCEPTION: main
05-24 10:57:11.108: E/AndroidRuntime(981): java.lang.RuntimeException: Unable to create application com.sentry.android.hmi.SentryApp: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.CallLogProvider from ProcessRecord{41321b58 981:com.sentry.android/u0a48} (pid=981, uid=10048) requires android.permission.READ_CALL_LOG or android.permission.WRITE_CALL_LOG
05-24 10:57:11.108: E/AndroidRuntime(981): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4154)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.app.ActivityThread.access$1300(ActivityThread.java:130)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.os.Handler.dispatchMessage(Handler.java:99)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.os.Looper.loop(Looper.java:137)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-24 10:57:11.108: E/AndroidRuntime(981): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 10:57:11.108: E/AndroidRuntime(981): at java.lang.reflect.Method.invoke(Method.java:511)
05-24 10:57:11.108: E/AndroidRuntime(981): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-24 10:57:11.108: E/AndroidRuntime(981): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-24 10:57:11.108: E/AndroidRuntime(981): at dalvik.system.NativeStart.main(Native Method)
05-24 10:57:11.108: E/AndroidRuntime(981): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.CallLogProvider from ProcessRecord{41321b58 981:com.sentry.android/u0a48} (pid=981, uid=10048) requires android.permission.READ_CALL_LOG or android.permission.WRITE_CALL_LOG
05-24 10:57:11.108: E/AndroidRuntime(981): at android.os.Parcel.readException(Parcel.java:1425)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.os.Parcel.readException(Parcel.java:1379)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2354)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.app.ActivityThread.acquireProvider(ActivityThread.java:4219)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:1703)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1099)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.content.ContentResolver.query(ContentResolver.java:354)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.content.ContentResolver.query(ContentResolver.java:313)
05-24 10:57:11.108: E/AndroidRuntime(981): at com.sentry.android.hmi.SentryApp.onCreate(SentryApp.java:116)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:999)
05-24 10:57:11.108: E/AndroidRuntime(981): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4151)
05-24 10:57:11.108: E/AndroidRuntime(981): ... 10 more
You have to add the following line to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.WRITE_CALL_LOG"/>
If you are just reading this log, change the line to:
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
Put this line above of your <application> tag. Or, if you have other permission entries as well, where those others are.
Those permissions were added with the API-Level 16. See for example the documentation to the value READ_CALL_LOG.
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()"
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.
I am using the codes below but my app force closes independently which one use. These are from several examples found on the net but none of them is working:
The semes2 variable is a phone number retrieved from the ContactsContract and is not null (verified by Toast msg).
Uri uri = Uri.fromParts("tel", semes2, null);
Intent callIntent = new Intent(Intent.ACTION_CALL, uri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);
or
Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:6365551212"));
startActivity(dialIntent);
or
Intent dialIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel://" + semes2));
dialIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialIntent);
In the manifest i have <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
What am i missing?
Edit: logcat:
05-24 05:46:17.404: ERROR/AndroidRuntime(272): FATAL EXCEPTION: main
05-24 05:46:17.404: ERROR/AndroidRuntime(272): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel://+36301111111 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{43f8e500 272:com.bfarago.nevnap/10048} (pid=272, uid=10048) requires android.permission.CALL_PHONE
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.os.Parcel.readException(Parcel.java:1247)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.os.Parcel.readException(Parcel.java:1235)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.app.Activity.startActivityForResult(Activity.java:2817)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.app.Activity.startActivity(Activity.java:2923)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at com.bfarago.nevnap.MainActivity$1$1$1.onClick(MainActivity.java:1363)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:874)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.widget.ListView.performItemClick(ListView.java:3382)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.os.Handler.handleCallback(Handler.java:587)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.os.Handler.dispatchMessage(Handler.java:92)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.os.Looper.loop(Looper.java:123)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at java.lang.reflect.Method.invoke(Method.java:521)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-24 05:46:17.404: ERROR/AndroidRuntime(272): at dalvik.system.NativeStart.main(Native Method)
05-24 05:46:17.564: WARN/ActivityManager(58): Force finishing activity com.bfarago.nevnap/.MainActivity
05-24 05:46:18.224: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{44011768 com.bfarago.nevnap/.MainActivity}
05-24 05:46:19.754: INFO/Process(272): Sending signal. PID: 272 SIG: 9
05-24 05:46:19.816: INFO/ActivityManager(58): Process com.bfarago.nevnap (pid 272) has died.
05-24 05:46:19.844: WARN/ActivityManager(58): Scheduling restart of crashed service com.bfarago.nevnap/.UpdateService in 5000ms
05-24 05:46:19.864: INFO/WindowManager(58): WIN DEATH: Window{43fac220 com.bfarago.nevnap/com.bfarago.nevnap.MainActivity paused=false}
05-24 05:46:19.864: INFO/WindowManager(58): WIN DEATH: Window{440383a8 com.bfarago.nevnap/com.bfarago.nevnap.MainActivity paused=false}
05-24 05:46:19.954: WARN/InputManagerService(58): Got RemoteException sending setActive(false) notification to pid 272 uid 10048
05-24 05:46:21.110: WARN/NotificationService(58): Object died trying to hide notification android.app.ITransientNotification$Stub$Proxy#43edd2c0 in package com.bfarago.nevnap
05-24 05:46:21.114: WARN/ActivityManager(58): setProcessForeground called on unknown pid: 272
05-24 05:46:24.944: INFO/ActivityManager(58): Start proc com.bfarago.nevnap for service com.bfarago.nevnap/.UpdateService: pid=286 uid=10048 gids={1015}
05-24 05:46:29.200: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{44011768 com.bfarago.nevnap/.MainActivity}
05-24 05:46:30.605: DEBUG/dalvikvm(162): GC_EXPLICIT freed 2438 objects / 143352 bytes in 192ms
Found the solution. Instead of ACTION_CALL i should have used ACTION_DIAL. I can also remove the // after tel:, it doesn't matter. So e.g.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + semes2));
startActivity(intent);
However, the 2nd example is still force closes even though it has ACTION DIAL.
You should include the following permission android.permission.CALL_PHONE in your android manifest file :
<uses-permission android:name="android.permission.CALL_PHONE"/>