Use old camera API on lollipop - android

I have an app that use Camera API that works perfectly on a nexus 7 with kitkat, but after update to lollipop my app crash.
I've decide to use new Camera2 API without success: code works well on a nexus5 but fail on nexus 7.
So i would use old API until i find out where's the problem with new api.
Portion of code that crash is when i initialize camera surface:
#SuppressWarnings("deprecation")
#SuppressLint("InlinedApi")
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
Camera.Parameters params = mCamera.getParameters();
Camera.Size result = getBestPreviewSize(params, width, height);
Log.i("TAG", surfaceView.getWidth() + " " + surfaceView.getHeight());
params.setPreviewSize(result.width, result.height);
params.setPictureFormat(ImageFormat.JPEG);
params.setJpegQuality(100);
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
// params.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
// params.setp
params.setPictureSize(dpWidth, dpWidth);
// default orientation is in landscape
params.setRotation(90);
mCamera.setParameters(params);
mCamera.startPreview();
}
crash is on setParameters() instruction:
12-18 10:44:54.130: E/AndroidRuntime(31543): FATAL EXCEPTION: main
12-18 10:44:54.130: E/AndroidRuntime(31543): Process: it.ictinnova.hipstamemostylist, PID: 31543
12-18 10:44:54.130: E/AndroidRuntime(31543): java.lang.RuntimeException: setParameters failed
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.hardware.Camera.native_setParameters(Native Method)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.hardware.Camera.setParameters(Camera.java:1876)
12-18 10:44:54.130: E/AndroidRuntime(31543): at it.ictinnova.hipstamemostylist.ScattaFoto.surfaceChanged(ScattaFoto.java:137)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.SurfaceView.updateWindow(SurfaceView.java:590)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1956)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.Choreographer.doCallbacks(Choreographer.java:580)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.Choreographer.doFrame(Choreographer.java:550)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.os.Handler.handleCallback(Handler.java:739)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.os.Handler.dispatchMessage(Handler.java:95)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.os.Looper.loop(Looper.java:135)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.app.ActivityThread.main(ActivityThread.java:5221)
12-18 10:44:54.130: E/AndroidRuntime(31543): at java.lang.reflect.Method.invoke(Native Method)
12-18 10:44:54.130: E/AndroidRuntime(31543): at java.lang.reflect.Method.invoke(Method.java:372)
12-18 10:44:54.130: E/AndroidRuntime(31543): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
12-18 10:44:54.130: E/AndroidRuntime(31543): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
What's wrong?
this is the same code i used on kitcat

what returns if there is not best preview size in the function of getBestPreviewSize().maybe,code control resolution of the display and the real machine test resolution is different.
try to annotate the code "params.setPreviewSize(result.width, result.height);" and run the code.

Related

Android: Runtime error: thread exiting with uncaught exception (group=0x4198ccf8)

I have created a form and am getting the following error message:
E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.*****.******, PID: 15427
java.lang.IllegalArgumentException: parameter must be a descendant of this view
at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:4779)
at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:4713)
at android.view.ViewRootImpl.scrollToRectOrFocus(ViewRootImpl.java:3017)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2641)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2587)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2210)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5345)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
The problem is the app will work half of the time and crash at other times, as in, being able to reproduce the same crash is not possible. I understand that its a runtime error; so how should I go about it?

After cleaning RAM app crashes when resuming android app (NullPointerException)

I have a problem with my app. I searched for a solution on stackoverflow, but i didn't find one.
I'm still a beginner in developing android apps. I created my first app on my own in the last week.
The problem: When I start the app everything works fine. Also when I start my app, go to menu and resume immediately, but when i switch to menu, clean my memory and then restart my app, it seems, that the app was still running, because it crashes now. I have a similar effect when I start the app, switch to some other apps and then return to my app. In this case, the app also crashes.
So, why the app is still running, altough I cleaned my memory? Should I override onFinish()- or onPause()-method with some basic code I don't know?
And why does the app crash, when i don't use it for a while?
LogCat:
12-18 23:19:06.850: E/AndroidRuntime(25262): FATAL EXCEPTION: main
12-18 23:19:06.850: E/AndroidRuntime(25262): java.lang.NullPointerException
12-18 23:19:06.850: E/AndroidRuntime(25262): at de.dzapps.isoapp.IsoToleranzen.update(IsoToleranzen.java:1293)
12-18 23:19:06.850: E/AndroidRuntime(25262): at de.dzapps.isoapp.IsoToleranzen$4.onItemClick(IsoToleranzen.java:441)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.widget.AbsListView.performItemClick(AbsListView.java:1283)
12-18 23:19:06.850: E/AndroidRuntime(25262): at de.dzapps.isoapp.IsoToleranzen$1.onGlobalLayout(IsoToleranzen.java:174)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:682)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1875)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1131)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4611)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.Choreographer.doFrame(Choreographer.java:525)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.os.Handler.handleCallback(Handler.java:615)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.os.Handler.dispatchMessage(Handler.java:92)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.os.Looper.loop(Looper.java:137)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-18 23:19:06.850: E/AndroidRuntime(25262): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 23:19:06.850: E/AndroidRuntime(25262): at java.lang.reflect.Method.invoke(Method.java:511)
12-18 23:19:06.850: E/AndroidRuntime(25262): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
12-18 23:19:06.850: E/AndroidRuntime(25262): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
12-18 23:19:06.850: E/AndroidRuntime(25262): at dalvik.system.NativeStart.main(Native Method)
Since I get a NullPointerException, it seems, that the system deletes the variables...
But when I doubleclick the third line, eclipse marks this line:
int am_offset = list.getChildAt(0).getTop();
I can't explain this behaviour, because I set a breakpoint at this line and the system never call this expression when I resume the app. list is a ListView.
How can I prevent, that the system deletes the variables, when then app is not used for a while?
Can somebody help me?
Many thanks!
From what I've read, the system deleting variables should be more or less left alone as the system does what it must to keep device performance. It may help to avoid these NullPointerExceptions and restore state by writing safety checks in the onResume of the activity to recreate any lost variables. Also, if they hold data that must persist for long periods of time, SharedPreferences may be of some use for small values and an SQLiteDatabase for when there's a lot to save.
ok I have a solution. I replaced int am_offset = list.getChildAt(0).getTop(); with:
View am_top = list.getChildAt(0);
am_offset = (am_top == null) ? 0 : am_top.getTop();
Now I don't get an exception anymore.
But can somebody explain to me, why the system throws an exception, altough int am_offset = list.getChildAt(0).getTop(); is never called while resuming?
Many thanks!

my app crashes after adding android:layout_below

i needed help in adding android:layout_below and after adding succesfully now my apps crashes when ever i start to see the result i hope you help me this is my code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/secondLine"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:text="#string/state1"
android:textSize="16sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#id/textView1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="#string/sayer1"
android:textSize="12sp" />
</RelativeLayout>
and this my logcat
12-18 13:57:18.581: D/AndroidRuntime(2237): Shutting down VM
12-18 13:57:18.581: W/dalvikvm(2237): threadid=1: thread exiting with uncaught exception (group=0x411e62a0)
12-18 13:57:18.581: E/AndroidRuntime(2237): FATAL EXCEPTION: main
12-18 13:57:18.581: E/AndroidRuntime(2237): java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1321)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:316)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:337)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-18 13:57:18.581: E/AndroidRuntime(2237): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2361)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1999)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1238)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1413)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1131)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4611)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.Choreographer.doFrame(Choreographer.java:525)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.os.Handler.handleCallback(Handler.java:615)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.os.Handler.dispatchMessage(Handler.java:92)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.os.Looper.loop(Looper.java:137)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-18 13:57:18.581: E/AndroidRuntime(2237): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 13:57:18.581: E/AndroidRuntime(2237): at java.lang.reflect.Method.invoke(Method.java:511)
12-18 13:57:18.581: E/AndroidRuntime(2237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
12-18 13:57:18.581: E/AndroidRuntime(2237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
12-18 13:57:18.581: E/AndroidRuntime(2237): at dalvik.system.NativeStart.main(Native Method)
android:layout_alignBottom="#+id/secondLine" // remove this
for textview1
and
android:layout_below="#id/textView1"
for textView2
causes
java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
Remove one of them and it should work
Place second TextView with id secondLine relative to TextView with id textview1. You have Circular dependencies which is not possible and hence the error.
You need to place once view relative to another.
You are assigning a textView1 to android:layout_alignBottom="#+id/secondLine"
and to second TextView you are assigning secondLine to android:layout_below="#id/textView1"
it mean you are assigning one textview to another and that second to first one.
this is creting Circular dependencies.
You can not assing TextView1 <--> TextView2 connections. you can assign only single side.
remove either of the line.
android:layout_alignBottom="#+id/secondLine"
or
android:layout_below="#id/textView1"
Both TextViews are pointing to each of them like android:layout_alignBottom="#+id/secondLine" and android:layout_below="#id/textView1" so it forms like circular loop, hence you are getting the error. Remove this android:layout_alignBottom="#+id/secondLine" from first textview

Run-time error "inflating class fragment"

I have an activity, what I'm trying to do is to start a new activity that holds a Google Maps Fragment API v2 following this example (https://developers.google.com/maps/documentation/android/start). I get an runtime error
"Binary XML file line #4: Error inflating class fragment"
This the XML of activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
and this is the activity's class:
import android.app.Activity;
import android.os.Bundle;
public class MapsActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_act);
// TODO Auto-generated method stub
}
}
and this is the logcat:
12-18 11:59:37.584: W/dalvikvm(9480): threadid=1: thread exiting with uncaught exception (group=0x2b6a3300)
12-18 11:59:37.594: E/AndroidRuntime(9480): FATAL EXCEPTION: main
12-18 11:59:37.594: E/AndroidRuntime(9480): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dimacroitori.supermarket/com.dimacroitori.supermarket.MapsActivity}: android.view.InflateException: Binary XML file line #4: Error inflating class fragment
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2190)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2215)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread.access$600(ActivityThread.java:144)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.os.Looper.loop(Looper.java:137)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread.main(ActivityThread.java:4939)
12-18 11:59:37.594: E/AndroidRuntime(9480): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 11:59:37.594: E/AndroidRuntime(9480): at java.lang.reflect.Method.invoke(Method.java:511)
12-18 11:59:37.594: E/AndroidRuntime(9480): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-18 11:59:37.594: E/AndroidRuntime(9480): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
12-18 11:59:37.594: E/AndroidRuntime(9480): at dalvik.system.NativeStart.main(Native Method)
12-18 11:59:37.594: E/AndroidRuntime(9480): Caused by: android.view.InflateException: Binary XML file line #4: Error inflating class fragment
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-18 11:59:37.594: E/AndroidRuntime(9480): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:257)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Activity.setContentView(Activity.java:1867)
12-18 11:59:37.594: E/AndroidRuntime(9480): at com.exmaple.MapsActivity.onCreate(MapsActivity.java:12)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Activity.performCreate(Activity.java:5008)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-18 11:59:37.594: E/AndroidRuntime(9480): ... 11 more
12-18 11:59:37.594: E/AndroidRuntime(9480): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Fragment.instantiate(Fragment.java:584)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Fragment.instantiate(Fragment.java:552)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Activity.onCreateView(Activity.java:4656)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
12-18 11:59:37.594: E/AndroidRuntime(9480): ... 20 more
12-18 11:59:37.594: E/AndroidRuntime(9480): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
12-18 11:59:37.594: E/AndroidRuntime(9480): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-18 11:59:37.594: E/AndroidRuntime(9480): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-18 11:59:37.594: E/AndroidRuntime(9480): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Fragment.instantiate(Fragment.java:574)
12-18 11:59:37.594: E/AndroidRuntime(9480): ... 23 more
Can someone explain me what I'm doing wrong?
Make sure that you have added the Google Play Services Android library project to your application, where that class is defined. Also make sure that you are running your app on an API Level 11 or higher environment, since you are attempting to use native fragments (rather than the Android Support package's backport).

Android app working in debug mode but not when installed

I'm new to Android development and I'm having a weird issue. I am trying to pull and display calendar events from an AsyncTask. This works in debug mode, but if I try to install the application through the apk the application crashes with this error :
12-18 08:57:16.768: E/AndroidRuntime(8642): FATAL EXCEPTION: AsyncTask #2
12-18 08:57:16.768: E/AndroidRuntime(8642): java.lang.RuntimeException: An error occured while executing doInBackground()
12-18 08:57:16.768: E/AndroidRuntime(8642): at android.os.AsyncTask$3.done(AsyncTask.java:299)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-18 08:57:16.768: E/AndroidRuntime(8642): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.lang.Thread.run(Thread.java:856)
12-18 08:57:16.768: E/AndroidRuntime(8642): Caused by: java.lang.IllegalArgumentException: unable to create new instance of class com.a.b.b.a.a.b because it has no accessible default constructor
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.e.aa.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.e.aa.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.e.i.b(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source) 12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.g.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.f.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.d.f.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.c.t.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.a.b.a.b.d.c.d(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.promevo.bookit.a.f(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.promevo.bookit.a.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.promevo.bookit.f.a(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at com.promevo.bookit.f.doInBackground(Unknown Source)
12-18 08:57:16.768: E/AndroidRuntime(8642): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-18 08:57:16.768: E/AndroidRuntime(8642): ... 5 more
12-18 08:57:16.768: E/AndroidRuntime(8642): Caused by: java.lang.InstantiationException: can't instantiate class com.a.b.b.a.a.b; no empty constructor
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.lang.Class.newInstanceImpl(Native Method)
12-18 08:57:16.768: E/AndroidRuntime(8642): at java.lang.Class.newInstance(Class.java:1319)
The call that I am making :
Events feed = client.events().list(CalendarSampleActivity.getCalId()).setTimeMin(startPass)
.setTimeMax(endPass).setSingleEvents(true).execute();
Anyone have any ideas? Thanks in advance.
Ok so after some troubleshooting it seems that something is going wrong when using Proguard. If I remove this line from my project.properties file, my application now works:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt:proguard-google-api-client.txt
Anyone know exactly why this would make a difference?
Read about Proguard and Android here: http://developer.android.com/tools/help/proguard.html
Since you are getting a "No accessible default constructor" exception it is most likely that Proguard has removed this constructor from the package because it couldn't find users of this constructor (Proguard removes inaccessible or unused code from the package to make it smaller). You will have to tell Proguard to keep certain code in the package even though it isn't obviously used.
The other alternative is to disable Proguard for release builds.

Categories

Resources