ActionBar and SearchView problems on the Android 2.3.5 - android

I have an ActionBar implemented as well as a SearchView widget in my app. It works just fine on the Nexus 7, HTC Sensation, etc. - anywhere where the Android version is older than 3.0 I believe. But it doesn't run on the phone with the Android 2.3.5.
Is there anyway to "not display" the action bar and other unsupported stuff when the program runs on the old device?
Here is the error log I get when run in on my old device, sorry for the length, don't really understand which bit is useful:
09-27 12:15:03.008: I/dalvikvm(824): Failed resolving Lcom/example/stroke/handling/MainActivity; interface 407 'Landroid/widget/SearchView$OnQueryTextListener;'
09-27 12:15:03.008: W/dalvikvm(824): Link of class 'Lcom/example/stroke/handling/MainActivity;' failed
09-27 12:15:03.008: D/AndroidRuntime(824): Shutting down VM
09-27 12:15:03.008: W/dalvikvm(824): threadid=1: thread exiting with uncaught exception (group=0x400205a0)
09-27 12:15:03.018: E/AndroidRuntime(824): FATAL EXCEPTION: main
09-27 12:15:03.018: E/AndroidRuntime(824): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.stroke.handling/com.example.stroke.handling.MainActivity}: java.lang.ClassNotFoundException: com.example.stroke.handling.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.stroke.handling-1.apk]
09-27 12:15:03.018: E/AndroidRuntime(824): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1743)
09-27 12:15:03.018: E/AndroidRuntime(824): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
09-27 12:15:03.018: E/AndroidRuntime(824): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
09-27 12:15:03.018: E/AndroidRuntime(824): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
09-27 12:15:03.018: E/AndroidRuntime(824): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 12:15:03.018: E/AndroidRuntime(824): at android.os.Looper.loop(Looper.java:150)
09-27 12:15:03.018: E/AndroidRuntime(824): at android.app.ActivityThread.main(ActivityThread.java:4277)
09-27 12:15:03.018: E/AndroidRuntime(824): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 12:15:03.018: E/AndroidRuntime(824): at java.lang.reflect.Method.invoke(Method.java:507)
09-27 12:15:03.018: E/AndroidRuntime(824): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-27 12:15:03.018: E/AndroidRuntime(824): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-27 12:15:03.018: E/AndroidRuntime(824): at dalvik.system.NativeStart.main(Native Method)
09-27 12:15:03.018: E/AndroidRuntime(824): Caused by: java.lang.ClassNotFoundException: com.example.stroke.handling.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.stroke.handling-1.apk]
09-27 12:15:03.018: E/AndroidRuntime(824): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
09-27 12:15:03.018: E/AndroidRuntime(824): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
09-27 12:15:03.018: E/AndroidRuntime(824): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-27 12:15:03.018: E/AndroidRuntime(824): at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
09-27 12:15:03.018: E/AndroidRuntime(824): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1735)
09-27 12:15:03.018: E/AndroidRuntime(824): ... 11 more
P.S. I don't want to use ActionBarSherlock!

Oopsie,
Remaining backward-compatible
If you want to provide an action bar in your application and remain
compatible with versions of Android older than 3.0, you need to create
the action bar in your activity's layout (because the ActionBar class
is not available on older versions).
To help you, the Action Bar Compatibility sample app provides an API
layer and action bar layout that allows your app to use some of the
ActionBar APIs and also support older versions of Android by replacing
the traditional title bar with a custom action bar layout.
Is it the answer to my question?
Edit: that sample app is shit.

You can check current os version and run code which is supported e.g.
if(android.os.Build.VERSION.SDK_INT < 11){
// use api available only in sdk < 11
}else{
// use api available in sdk 11
}

You can use
http://actionbarsherlock.com/
and add support library to your project, then the action bar will work on 1.6 and above

This is to inform you that, you should use Action Bar Sherlock for the same. It is very awesome feature/library provided by the John Watson.
And do refer to this slide share tutorial. It will definitely help you.
Let me know if you have any further queries regarding Action Bar Sherlock.
Thanks

You just need to add android-support-v7-appcompat.jar
Then use "android.support.v7.widget.SearchView"
http://developer.android.com/reference/android/support/v7/widget/SearchView.html

Related

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));
}

How to avoid class not found exception in android

I am getting class not found exception on some android devices, it's happening only on some devices.
This is the call-stack i have got,
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.picframes.android/com.picframes.android.first}: java.lang.ClassNotFoundException: com.picframes.android.first
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:4987)
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.ClassNotFoundException: com.picframes.android.first
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1039)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
Any suggestions for resolving this problem, I could not reproduce this problem on my device.
On devices with which android version program works and where it doesn't work? I am not sure if this is the case but you probably get this error on older devices, is that right? You should make sure that all the functionality of your program is available on older systems. Use your manifest file:
<uses-sdk android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
to define minimum sdk version, and you will get errors in your code if you are trying to use features that are not available on the device that you target.

When people download my app from the google play i get this error: java.lang.RuntimeException: Unable to instantiate activity

my name is Walid.
im having this error when people download my app from google play i get this error
i think its when certain devices download the app it causes the app to crash .
this is the sdk in the manifest.
please if anyone knows how to fix this please let me know .
Thank you.
<uses-sdk
android:minSdkVersion="2"
android:targetSdkVersion="17" />
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{tigris.code.oneallah.walid/tigris.code.oneallah.walid.MenuPage}: java.lang.ClassNotFoundException: tigris.code.oneallah.walid.MenuPage in loader dalvik.system.PathClassLoader[/data/app/tigris.code.oneallah.walid-1.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3693)
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:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: tigris.code.oneallah.walid.MenuPage in loader dalvik.system.PathClassLoader[/data/app/tigris.code.oneallah.walid-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
... 11 more
Your APK file does not contain a class named tigris.code.oneallah.walid.MenuPage. Either the APK is missing the class, or ProGuard renamed it.

Unable to start activity On Sony Experia S

I recently published my app to the android play store.
I see a whole lot of error logs from one device in particular. It's a Sony Experia S.
I contacted the owner of the device, and he says he has the latest version of android ( don't know the exact version ).
I heard from a colluege developer that there are more known issieus with sony devices and android.
This app in particular works with fragments... Don't know if this is the problem but... Maybe the sony's don't know how to cope with them.
Does anyone have an idea what this problem could be.
Error logs looks like:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.crosscommunications.kvodeventer/com.crosscommunications.kvodeventer.KVODeventerActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.crosscommunications.kvodeventer/com.crosscommunications.kvodeventer.TabControllerHome}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4511)
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:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.crosscommunications.kvodeventer/com.crosscommunications.kvodeventer.TabControllerHome}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:1808)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:682)
at android.widget.TabHost.setCurrentTab(TabHost.java:346)
at android.widget.TabHost.addTab(TabHost.java:236)
at com.crosscommunications.kvodeventer.KVODeventerActivity.onCreate(KVODeventerActivity.java:27)
at android.app.Activity.performCreate(Activity.java:4470)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
... 11 more
Caused by: java.lang.NullPointerException
at com.crosscommunications.kvodeventer.KVOHome.onCreateView(KVOHome.java:52)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:505)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1136)
at android.app.Activity.performStart(Activity.java:4480)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1940)
... 21 more
Thnx
Just put a null check to your code:
KVOHome Acvitivity, line 52.
at com.crosscommunications.kvodeventer.KVOHome.onCreateView(KVOHome.java:52)
Most probably, Sony sends a null value to your code.

Zxing change the action intent

I added the Zxing library to my android app but there is a problem.
When you already have a bar code scanner installed it presents you
with a popup.
I don't want this to happen and changed the the action intent.
This is working, but when I open my app for the first time and select
the bar code scanner it crashes.
When I open it for the second time everything works fine.
Can anybody please help me?
I've already answered this a few times on the mailing list. As I said, you need to pay attention to ActivityNotFoundException.
09-27 16:52:54.046 E/AndroidRuntime( 4949): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {nl.everybodylikespenguins/com.google.zxing.client.android.HelpActivity}; have you declared this activity in your AndroidManifest.xml?
09-27 16:52:54.046 E/AndroidRuntime( 4949): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
09-27 16:52:54.046 E/AndroidRuntime( 4949): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
09-27 16:52:54.046 E/AndroidRuntime( 4949): at android.app.Activity.startActivityForResult(Activity.java:2789)
09-27 16:52:54.046 E/AndroidRuntime( 4949): at android.app.Activity.startActivity(Activity.java:2895)
09-27 16:52:54.046 E/AndroidRuntime( 4949): at com.google.zxing.client.android.CaptureActivity.showHelpOnFirstLaunch(CaptureActivity.java:595)
09-27 16:52:54.046 E/AndroidRuntime( 4949): at com.google.zxing.client.android.CaptureActivity.onCreate(CaptureActivity.java:169)
09-27 16:52:54.046 E/AndroidRuntime( 4949): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-27 16:52:54.046 E/AndroidRuntime( 4949): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
Android throws this when you start an intent for which there is no app, and that's what's happening here. You need to handle this yourself by catching the exception and, maybe, sending the user to Market to download.
This is exactly what the code in android-integration in zxing does, which is why I also already told you to look at that.

Categories

Resources