Application runs fine on emulator but gives NoClassDefFoundError on device - android

I have developed an app and it runs as expected on the emulator, but gives error while I run it in my device(HTC one X). Below is the error as shown in the logcat. There is a method which creates a notification. Error appears when this method createNotification() is invoked. Logcat is below:
11-09 13:40:13.350: E/AndroidRuntime(5294): FATAL EXCEPTION: main
11-09 13:40:13.350: E/AndroidRuntime(5294): java.lang.NoClassDefFoundError: android.app.TaskStackBuilder
11-09 13:40:13.350: E/AndroidRuntime(5294): at com.example.accessibility.Accessibility.createNotification(Accessibility.java:205)
11-09 13:40:13.350: E/AndroidRuntime(5294): at com.example.accessibility.Accessibility$1.onClick(Accessibility.java:69)
11-09 13:40:13.350: E/AndroidRuntime(5294): at android.view.View.performClick(View.java:3538)
11-09 13:40:13.350: E/AndroidRuntime(5294): at android.view.View$PerformClick.run(View.java:14319)
11-09 13:40:13.350: E/AndroidRuntime(5294): at android.os.Handler.handleCallback(Handler.java:608)
11-09 13:40:13.350: E/AndroidRuntime(5294): at android.os.Handler.dispatchMessage(Handler.java:92)
11-09 13:40:13.350: E/AndroidRuntime(5294): at android.os.Looper.loop(Looper.java:156)
11-09 13:40:13.350: E/AndroidRuntime(5294): at android.app.ActivityThread.main(ActivityThread.java:5045)
11-09 13:40:13.350: E/AndroidRuntime(5294): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 13:40:13.350: E/AndroidRuntime(5294): at java.lang.reflect.Method.invoke(Method.java:511)
11-09 13:40:13.350: E/AndroidRuntime(5294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-09 13:40:13.350: E/AndroidRuntime(5294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-09 13:40:13.350: E/AndroidRuntime(5294): at dalvik.system.NativeStart.main(Native Method)
I would appreciate if someone can help me fix this error.

TaskStackBuilder is available starting from API level 16 (Android 4.1 otherwise known as Jellybean). Your HTC One X has Android 4.0 on it.

As mentioned by #David Wasser TaskStackBuilder was added in API Level 16 (Android 4.1)
You can solve your problem by adding import android.support.v4.app.TaskStackBuilder; instead of import android.app.TaskStackBuilder;
make sure your app having either v4 / v7 support library added

Related

Application unfortunately closed on xperia p mobile with api level 14

When i am debugging my application on emulator which is of api level 14(4.0) the application is working fine, but when i am debugging same application on xperia p api level 14(4.0.4)) application has stopped unfortunately, and same application debugging on Samsung duos its working properly, application is working fine with emulator and samsung mobile af api level 14 but why its unfortunately stopped on xperia p with api level 14?
Please help me to understand this issue.
Below is the log:
11-09 13:22:30.678: E/AndroidRuntime(7456): FATAL EXCEPTION: main
11-09 13:22:30.678: E/AndroidRuntime(7456): java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY.
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:591)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.view.View.measure(View.java:12911)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:599)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:381)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.view.View.measure(View.java:12911)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.widget.ScrollView.onMeasure(ScrollView.java:336)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.view.View.measure(View.java:12911)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4805)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.widget.FrameLayout.onMeasure(FrameLayout.java:297)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.view.View.measure(View.java:12911)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.widget.LinearLayout.measureVertical(LinearLayout.java:828)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.widget.LinearLayout.onMeasure(LinearLayout.java:557)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.view.View.measure(View.java:12911)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4805)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.widget.FrameLayout.onMeasure(FrameLayout.java:297)
11-09 13:22:30.678: E/AndroidRuntime(7456): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2097)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.view.View.measure(View.java:12911)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.os.Looper.loop(Looper.java:137)
11-09 13:22:30.678: E/AndroidRuntime(7456): at android.app.ActivityThread.main(ActivityThread.java:4441)
11-09 13:22:30.678: E/AndroidRuntime(7456): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 13:22:30.678: E/AndroidRuntime(7456): at java.lang.reflect.Method.invoke(Method.java:511)
11-09 13:22:30.678: E/AndroidRuntime(7456): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
11-09 13:22:30.678: E/AndroidRuntime(7456): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
11-09 13:22:30.678: E/AndroidRuntime(7456): at dalvik.system.NativeStart.main(Native Method)

error while locating my current location

I am developing application to get my current location on the map and display the nearest places.
first my application was running but the camera goes at fixed Latlng ( i put the values) but when i change the code to make the camera on my current location .. my phone shutting down.
This is my logcat:
11-09 08:38:51.010: E/AndroidRuntime(1641): FATAL EXCEPTION: main
11-09 08:38:51.010: E/AndroidRuntime(1641): java.lang.NullPointerException
11-09 08:38:51.010: E/AndroidRuntime(1641): at com.example.buttontest.NearbyActivity.onConnected(NearbyActivity.java:219)
11-09 08:38:51.010: E/AndroidRuntime(1641): at com.google.android.gms.internal.u.v(Unknown Source)
11-09 08:38:51.010: E/AndroidRuntime(1641): at com.google.android.gms.internal.u$f.a(Unknown Source)
11-09 08:38:51.010: E/AndroidRuntime(1641): at com.google.android.gms.internal.u$f.a(Unknown Source)
11-09 08:38:51.010: E/AndroidRuntime(1641): at com.google.android.gms.internal.u$b.A(Unknown Source)
11-09 08:38:51.010: E/AndroidRuntime(1641): at com.google.android.gms.internal.u$a.handleMessage(Unknown Source)
11-09 08:38:51.010: E/AndroidRuntime(1641): at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 08:38:51.010: E/AndroidRuntime(1641): at android.os.Looper.loop(Looper.java:137)
11-09 08:38:51.010: E/AndroidRuntime(1641): at android.app.ActivityThread.main(ActivityThread.java:4898)
11-09 08:38:51.010: E/AndroidRuntime(1641): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 08:38:51.010: E/AndroidRuntime(1641): at java.lang.reflect.Method.invoke(Method.java:511)
11-09 08:38:51.010: E/AndroidRuntime(1641): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
11-09 08:38:51.010: E/AndroidRuntime(1641): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
11-09 08:38:51.010: E/AndroidRuntime(1641): at dalvik.system.NativeStart.main(Native Method)
This is where the error
#Override
public void onConnected(Bundle dataBundle) {
// Display the connection status
Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
Location location = mLocationClient.getLastLocation();
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 17);
map.animateCamera(cameraUpdate);
}
NullPointerException is thrown because there might be a possibility that the location you got here Location location = mLocationClient.getLastLocation(); is null. Hence you might always do a null-check.

Selecting an item in ListFragment list programmatically

I've made my Android app tablet optimized and I followed the tutorial here:
Everything is great, but I am trying to select an item (say, the 1st item) with a button in the ActionBar.
I tried this answer to use performItemClick but on I've got error reports of java.lang.IllegalStateException
in android.support.v4.app.ListFragment.ensureList, java.lang.IllegalStateException: Content view not yet created, and java.lang.NullPointerException
in android.content.ComponentName.<init>
I've tried checking if the ListView is null and still get the error reports on the Play Store. How do I properly select an item in my list programmatically?
Update to add logcat and the code is virtually identical to the tutorials in the links:
Logcat A:
java.lang.IllegalStateException: Content view not yet created
at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:69)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2606)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1045)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:592)
at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:149)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17273)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
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:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Logcat B:
java.lang.NullPointerException
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:2874)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:86)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3701)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2205)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:779)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:861)
at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
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:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Update 2
And here is the code that is causing the problem:
if (mListFragment.listView != null) {
mListFragment.listView.performItemClick(mListFragment.listView.getAdapter().getView(position, null, null), position, mListFragment.listView.getAdapter().getItemId(position));
}

ZXing integration with eclipse and android, NoClassDefFoundError

I hae the same problem as all this topics about the problems of getting zxing working on a project in android, but none of the solutions worked for me. This is the error log:
11-09 11:06:16.009: E/AndroidRuntime(3481): FATAL EXCEPTION: main
11-09 11:06:16.009: E/AndroidRuntime(3481): java.lang.NoClassDefFoundError: com.google.zxing.client.android.R$layout
11-09 11:06:16.009: E/AndroidRuntime(3481): at com.google.zxing.client.android.CaptureActivity.onCreate(CaptureActivity.java:155)
11-09 11:06:16.009: E/AndroidRuntime(3481): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-09 11:06:16.009: E/AndroidRuntime(3481): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
11-09 11:06:16.009: E/AndroidRuntime(3481): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
11-09 11:06:16.009: E/AndroidRuntime(3481): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
11-09 11:06:16.009: E/AndroidRuntime(3481): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
11-09 11:06:16.009: E/AndroidRuntime(3481): at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 11:06:16.009: E/AndroidRuntime(3481): at android.os.Looper.loop(Looper.java:130)
11-09 11:06:16.009: E/AndroidRuntime(3481): at android.app.ActivityThread.main(ActivityThread.java:3835)
11-09 11:06:16.009: E/AndroidRuntime(3481): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 11:06:16.009: E/AndroidRuntime(3481): at java.lang.reflect.Method.invoke(Method.java:507)
11-09 11:06:16.009: E/AndroidRuntime(3481): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
11-09 11:06:16.009: E/AndroidRuntime(3481): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
11-09 11:06:16.009: E/AndroidRuntime(3481): at dalvik.system.NativeStart.main(Native Method)
I have tried lots of combinations inside buildpath, adding the source project, adding de core.jar (named zxing-1.7.jar in my project), addiing it as external library...but when i don't get this problem at the bottom, then i get a dalvik format error, saying Lcom/zxing/android: already added.
I have also tried to put the .jar inside a folder called libs, but none working, checking and unchecking it on build path configs.
here's an image of my current Build Path order, http://postimage.org/image/f496ukwkf/ , but i tried with lots of different combinations, and none of them worked.
Thanks, i need to get it working, please.
You are trying to include code from android/ in your project. You're not intended to do this, and you haven't set it up correctly either. Integrating by Intent (http://code.google.com/p/zxing/wiki/ScanningViaIntent) is far easier if you are new to this. No library code to mess with.

location-based application development testing on actual device

I am trying an example given in o reilys book and testing it on LG P500 but all I get is force close with the following errors:
WARNING: Application does not specify an API level requirement!
[2011-11-09 15:43:38 - dloc] Device API version is 8 (Android 2.2.2)
**p.s i have mentioned api level**
**logcat:**
11-09 16:00:44.738: W/dalvikvm(8002): threadid=1: thread exiting with uncaught exception (group=0x40020ac0)
11-09 16:00:44.738: E/AndroidRuntime(8002): FATAL EXCEPTION: main
11-09 16:00:44.738: E/AndroidRuntime(8002): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.microjobsinc.dloc/com.microjobsinc.dloc.Main}: java.lang.ClassNotFoundException: com.microjobsinc.dloc.Main in loader dalvik.system.PathClassLoader[/data/app/com.microjobsinc.dloc-2.apk]
11-09 16:00:44.738: E/AndroidRuntime(8002): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-09 16:00:44.738: E/AndroidRuntime(8002): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-09 16:00:44.738: E/AndroidRuntime(8002): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-09 16:00:44.738: E/AndroidRuntime(8002): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-09 16:00:44.738: E/AndroidRuntime(8002): at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 16:00:44.738: E/AndroidRuntime(8002): at android.os.Looper.loop(Looper.java:123)
11-09 16:00:44.738: E/AndroidRuntime(8002): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-09 16:00:44.738: E/AndroidRuntime(8002): at java.lang.reflect.Method.invokeNative(Native Method)
11-09 16:00:44.738: E/AndroidRuntime(8002): at java.lang.reflect.Method.invoke(Method.java:521)
11-09 16:00:44.738: E/AndroidRuntime(8002): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-09 16:00:44.738: E/AndroidRuntime(8002): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-09 16:00:44.738: E/AndroidRuntime(8002): at dalvik.system.NativeStart.main(Native Method)
11-09 16:00:44.738: E/AndroidRuntime(8002): Caused by: java.lang.ClassNotFoundException: com.microjobsinc.dloc.Main in loader dalvik.system.PathClassLoader[/data/app/com.microjobsinc.dloc-2.apk]
11-09 16:00:44.738: E/AndroidRuntime(8002): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
11-09 16:00:44.738: E/AndroidRuntime(8002): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
11-09 16:00:44.738: E/AndroidRuntime(8002): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
11-09 16:00:44.738: E/AndroidRuntime(8002): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-09 16:00:44.738: E/AndroidRuntime(8002): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
11-09 16:00:44.738: E/AndroidRuntime(8002): ... 11 more
11-09 16:00:49.848: W/dalvikvm(8013): threadid=1: thread exiting with uncaught exception (group=0x40020ac0)
11-09 16:00:49.858: E/AndroidRuntime(8013): FATAL EXCEPTION: main
Code is written below
public class main extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// find the TextViews
TextView tvLatitude = (TextView)findViewById(R.id.tvLatitude);
TextView tvLongitude = (TextView)findViewById(R.id.tvLongitude);
// get handle for LocationManager
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
// connect to the GPS location service
String providerName = LocationManager.GPS_PROVIDER;
Location loc = lm.getLastKnownLocation( providerName);
// fill in the TextViews
tvLatitude.setText(Double.toString(loc.getLatitude()));
tvLongitude.setText(Double.toString(loc.getLongitude()));
}
}
What is the cause of this problem and how can I fix it?
You need to change the android project properties to use Google Apis with the platform version that you desire.

Categories

Resources