getting position of database item from non list view view? - android

I have Views that show info from a database using a get cursor method. What I want to know is how to get the position id, like you would in a listview. they have the AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();, item being MenuItem, type of method the problem is it doesn't seem to work in just a regular view. Is there a method similar to the AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); for just a regular view?
Edit
log cat
03-14 08:55:43.738: E/AndroidRuntime(11177): FATAL EXCEPTION: main
03-14 08:55:43.738: E/AndroidRuntime(11177): java.lang.NullPointerException
03-14 08:55:43.738: E/AndroidRuntime(11177): at www.theapp.co.hours.html.ViewHours.onClick(ViewHours.java:6041)
03-14 08:55:43.738: E/AndroidRuntime(11177): at android.view.View.performClick(View.java:2408)
03-14 08:55:43.738: E/AndroidRuntime(11177): at android.view.View$PerformClick.run(View.java:8816)
03-14 08:55:43.738: E/AndroidRuntime(11177): at android.os.Handler.handleCallback(Handler.java:587)
03-14 08:55:43.738: E/AndroidRuntime(11177): at android.os.Handler.dispatchMessage(Handler.java:92)
03-14 08:55:43.738: E/AndroidRuntime(11177): at android.os.Looper.loop(Looper.java:123)
03-14 08:55:43.738: E/AndroidRuntime(11177): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-14 08:55:43.738: E/AndroidRuntime(11177): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 08:55:43.738: E/AndroidRuntime(11177): at java.lang.reflect.Method.invoke(Method.java:521)
03-14 08:55:43.738: E/AndroidRuntime(11177): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
03-14 08:55:43.738: E/AndroidRuntime(11177): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-14 08:55:43.738: E/AndroidRuntime(11177): at dalvik.system.NativeStart.main(Native Method)

Is there a method similar to the AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); for just a regular view?
No. If you, say, elect to pour Cursor data in to a TextView, you need to track what position or _id you used yourself. After all, you were the one who chose which position or _id to move to -- Android has no way of knowing if you populate a TextView from a Cursor or something else.

Related

card io integrated with paypal sdk is not working

I have integrated Paypal Sdk in my android app.It is having two options to pay using Paypal user account and to pay using credit card.Payment with credit can be done by card Io library but don't know why it is not working.Not working means it is not scanning card.Please tell me how to use it .I just keep card in front of long time but it does not fetch the details from the card .
SDK version 2.0.2
Logcat while scanning card
03-14 11:05:20.000: E/mm-camera(140): Ignoring execution of AEC as AF is active
03-14 11:05:20.060: E/mm-camera(140): Ignoring execution of AEC as AF is active
03-14 11:05:20.110: E/mm-camera(140): Ignoring execution of AEC as AF is active
03-14 11:05:20.110: W/QCameraHWI_Preview(132): android::status_t android::QCameraStream_preview::processPreviewFrameWithDisplay(mm_camera_ch_data_buf_t*): dis_proc_time 0ms, asd_proc_time 0ms, gpu_proc_time 0ms, face_proc_time 3ms, genlock_unlock_time 0ms, genlock_lock_time 0ms, enqueue_time 3ms, dequeue_time 0ms, ion_flush_time 2ms, lock_buffer_time 0ms, buf_done_time 8ms, data_callback_time 27ms, frame_proc_time 46ms
Even not able to made transaction by filling card details .App is getting crash
Logcat after filling card details :
03-14 11:09:23.370: E/AndroidRuntime(25350): java.lang.NullPointerException
03-14 11:09:23.370: E/AndroidRuntime(25350): at com.paypal.android.sdk.payments.PayPalService.h(Unknown Source)
03-14 11:09:23.370: E/AndroidRuntime(25350): at com.paypal.android.sdk.payments.PaymentMethodActivity.a(Unknown Source)
03-14 11:09:23.370: E/AndroidRuntime(25350): at com.paypal.android.sdk.payments.PaymentMethodActivity.f(Unknown Source)
03-14 11:09:23.370: E/AndroidRuntime(25350): at com.paypal.android.sdk.payments.aj.onServiceConnected(Unknown Source)
03-14 11:09:23.370: E/AndroidRuntime(25350): at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1187)
03-14 11:09:23.370: E/AndroidRuntime(25350): at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1204)
03-14 11:09:23.370: E/AndroidRuntime(25350): at android.os.Handler.handleCallback(Handler.java:615)
03-14 11:09:23.370: E/AndroidRuntime(25350): at android.os.Handler.dispatchMessage(Handler.java:92)
03-14 11:09:23.370: E/AndroidRuntime(25350): at android.os.Looper.loop(Looper.java:155)
03-14 11:09:23.370: E/AndroidRuntime(25350): at android.app.ActivityThread.main(ActivityThread.java:5520)
03-14 11:09:23.370: E/AndroidRuntime(25350): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 11:09:23.370: E/AndroidRuntime(25350): at java.lang.reflect.Method.invoke(Method.java:511)
03-14 11:09:23.370: E/AndroidRuntime(25350): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
03-14 11:09:23.370: E/AndroidRuntime(25350): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
03-14 11:09:23.370: E/AndroidRuntime(25350): at dalvik.system.NativeStart.main(Native Method)
03-14 11:09:23.380: E/EmbeddedLogger(343): App crashed! Process: com.paypal.example.paypalandroidsdkexample
03-14 11:09:23.380: E/EmbeddedLogger(343): App crashed! Package: com.paypal.example.paypalandroidsdkexample v1 (1.0)
03-14 11:09:23.380: E/EmbeddedLogger(343): Application Label: PayPal SDK Example
03-14 11:09:26.480: E/ThermalDaemon(25739): Thermal daemon started

Openx Android layout issue

I am attempting to display OpenX ads within an Android application. I have installed the SDK and followed the video found here. Everything is going smoothly, except when I edit the layout. I am constantly greeted with this friendly error message in the error log.
eclipse.buildId=M20120914-1800
java.version=1.7.0_11
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Command-line arguments: -os win32 -ws win32 -arch x86_64
Error
Thu Mar 14 17:40:44 PDT 2013
com.openx.ad.mobile.sdk.views.OXMAdBanner failed to instantiate.
java.lang.NullPointerException
at com.openx.ad.mobile.sdk.controllers.OXMAdBaseController.<init>(OXMAdBaseController.java:130)
at com.openx.ad.mobile.sdk.controllers.OXMAdController.<init>(OXMAdController.java:37)
at com.openx.ad.mobile.sdk.views.OXMAdBanner.init(OXMAdBanner.java:141)
at com.openx.ad.mobile.sdk.views.OXMAdBanner.reflectAttrs(OXMAdBanner.java:136)
at com.openx.ad.mobile.sdk.views.OXMAdBanner.<init>(OXMAdBanner.java:86)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:422)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:179)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:746)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:749)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:372)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:385)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:332)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:440)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1545)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1302)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:1059)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:686)
at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:360)
at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:292)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3023)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1730)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:270)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1029)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
I can't find any help on Google, and I am wondering if anyone has had this issue before. I have my manifest set up properly, and am running android:targetSdkVersion="17"
<activity
android:name="com.openx.ad.mobile.sdk.OXMAdBrowser"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
So since there are no build errors, I am able to launch my app, but it quickly creahses and throws some errors.
03-14 17:45:35.517: E/AndroidRuntime(23227): FATAL EXCEPTION: main
03-14 17:45:35.517: E/AndroidRuntime(23227): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.portlandtribune.pamplinmedia_beta/com.portlandtribune.pamplinmedia_beta.PM_section}: android.view.InflateException: Binary XML file line #97: Error inflating class com.openx.ad.mobile.sdk.views.OXMAdBanner
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.os.Looper.loop(Looper.java:137)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-14 17:45:35.517: E/AndroidRuntime(23227): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 17:45:35.517: E/AndroidRuntime(23227): at java.lang.reflect.Method.invoke(Method.java:511)
03-14 17:45:35.517: E/AndroidRuntime(23227): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-14 17:45:35.517: E/AndroidRuntime(23227): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-14 17:45:35.517: E/AndroidRuntime(23227): at dalvik.system.NativeStart.main(Native Method)
03-14 17:45:35.517: E/AndroidRuntime(23227): Caused by: android.view.InflateException: Binary XML file line #97: Error inflating class com.openx.ad.mobile.sdk.views.OXMAdBanner
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-14 17:45:35.517: E/AndroidRuntime(23227): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
03-14 17:45:35.517: E/AndroidRuntime(23227): at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:119)
03-14 17:45:35.517: E/AndroidRuntime(23227): at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:229)
03-14 17:45:35.517: E/AndroidRuntime(23227): at com.portlandtribune.pamplinmedia_beta.PM_section.onCreate(PM_section.java:145)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.app.Activity.performCreate(Activity.java:5008)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
03-14 17:45:35.517: E/AndroidRuntime(23227): ... 11 more
03-14 17:45:35.517: E/AndroidRuntime(23227): Caused by: java.lang.reflect.InvocationTargetException
03-14 17:45:35.517: E/AndroidRuntime(23227): at java.lang.reflect.Constructor.constructNative(Native Method)
03-14 17:45:35.517: E/AndroidRuntime(23227): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-14 17:45:35.517: E/AndroidRuntime(23227): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-14 17:45:35.517: E/AndroidRuntime(23227): ... 24 more
03-14 17:45:35.517: E/AndroidRuntime(23227): Caused by: java.lang.NullPointerException
03-14 17:45:35.517: E/AndroidRuntime(23227): at com.openx.ad.mobile.sdk.controllers.OXMAdBaseController.<init>(OXMAdBaseController.java:161)
03-14 17:45:35.517: E/AndroidRuntime(23227): at com.openx.ad.mobile.sdk.controllers.OXMAdController.<init>(OXMAdController.java:37)
03-14 17:45:35.517: E/AndroidRuntime(23227): at com.openx.ad.mobile.sdk.views.OXMAdBanner.init(OXMAdBanner.java:141)
03-14 17:45:35.517: E/AndroidRuntime(23227): at com.openx.ad.mobile.sdk.views.OXMAdBanner.reflectAttrs(OXMAdBanner.java:136)
03-14 17:45:35.517: E/AndroidRuntime(23227): at com.openx.ad.mobile.sdk.views.OXMAdBanner.<init>(OXMAdBanner.java:86)
Has anyone else had this issue?
Other information
I am using the standard code for the xml layout file. I know I haven't specified any details but it shouldn't be returning a com.openx.ad.mobile.sdk.views.OXMAdBanner failed to instantiate error. Right?
<com.openx.ad.mobile.sdk.views.OXMAdBanner
android:id="#+id/banner"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_gravity="center_horizontal|center_vertical"
domain="d.example.com"
portrait_id="1234"
landscape_id="4321"
change_interval="30000" />

Email sending from android application

I am trying to send Email from my android app from background.Mail was sent successfully with attachment but still after that i am getting error in log.Here is the log please guide me where is the error and how to resolve it.
03-14 13:37:37.697: E/MailApp(1296): Could not send email
03-14 13:37:37.697: E/MailApp(1296): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
03-14 13:37:37.697: E/MailApp(1296): at android.os.Handler.<init>(Handler.java:197)
03-14 13:37:37.697: E/MailApp(1296): at android.os.Handler.<init>(Handler.java:111)
03-14 13:37:37.697: E/MailApp(1296): at android.widget.Toast$TN.<init>(Toast.java:324)
03-14 13:37:37.697: E/MailApp(1296): at android.widget.Toast.<init>(Toast.java:91)
03-14 13:37:37.697: E/MailApp(1296): at android.widget.Toast.makeText(Toast.java:238)
03-14 13:37:37.697: E/MailApp(1296): at com.example.mytest.ReadContactsActivity.SendMail(ReadContactsActivity.java:173)
03-14 13:37:37.697: E/MailApp(1296): at com.example.mytest.ReadContactsActivity.access$0(ReadContactsActivity.java:156)
03-14 13:37:37.697: E/MailApp(1296): at com.example.mytest.ReadContactsActivity$CountDownTask.doInBackground(ReadContactsActivity.java:131)
03-14 13:37:37.697: E/MailApp(1296): at com.example.mytest.ReadContactsActivity$CountDownTask.doInBackground(ReadContactsActivity.java:1)
03-14 13:37:37.697: E/MailApp(1296): at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-14 13:37:37.697: E/MailApp(1296): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
03-14 13:37:37.697: E/MailApp(1296): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-14 13:37:37.697: E/MailApp(1296): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
03-14 13:37:37.697: E/MailApp(1296): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
I think you are trying to display Toast message inside the AsynTask doInBackground() method,
just do it in onPostExecute() method....
You might be using some background thread which is directly trying to make change in your main thread, if that is the issue then use
runOnUiThread(new Runnable() {
public void run() {
//do your work here
}
});

Nullpointer exception in listview adapter

I am using arrayadapter to show data on listview.What i have coded is shown below bt i am getting null pointer exception .Please tell me what i have missed ?
ArrayAdapter<String> adapter;
setContentView(R.layout.menu_home_activity);
OptionsList = (ListView) findViewById(R.id.OptionsLists);
String[] array = getResources().getStringArray(R.array.personal_settings);
adapter = new ArrayAdapter<String>(MenuHomeActivity.this,
R.layout.menu_home_activity, R.id.text, array);
OptionsList.setAdapter(adapter);
menu_home_activity.xml
<?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" >
<ListView
android:name="#+id/OptionsLists"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Logcat says :
03-14 10:54:59.242: E/AndroidRuntime(267): Uncaught handler: thread main exiting due to uncaught exception
03-14 10:54:59.252: E/AndroidRuntime(267): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.biz.elife/com.biz.elife.MenuHomeActivity}: java.lang.NullPointerException
03-14 10:54:59.252: E/AndroidRuntime(267): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
03-14 10:54:59.252: E/AndroidRuntime(267): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-14 10:54:59.252: E/AndroidRuntime(267): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-14 10:54:59.252: E/AndroidRuntime(267): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-14 10:54:59.252: E/AndroidRuntime(267): at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 10:54:59.252: E/AndroidRuntime(267): at android.os.Looper.loop(Looper.java:123)
03-14 10:54:59.252: E/AndroidRuntime(267): at android.app.ActivityThread.main(ActivityThread.java:4363)
03-14 10:54:59.252: E/AndroidRuntime(267): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 10:54:59.252: E/AndroidRuntime(267): at java.lang.reflect.Method.invoke(Method.java:521)
03-14 10:54:59.252: E/AndroidRuntime(267): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-14 10:54:59.252: E/AndroidRuntime(267): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-14 10:54:59.252: E/AndroidRuntime(267): at dalvik.system.NativeStart.main(Native Method)
03-14 10:54:59.252: E/AndroidRuntime(267): Caused by: java.lang.NullPointerException
03-14 10:54:59.252: E/AndroidRuntime(267): at com.biz.elife.MenuHomeActivity.onCreate(MenuHomeActivity.java:33)
03-14 10:54:59.252: E/AndroidRuntime(267): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-14 10:54:59.252: E/AndroidRuntime(267): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-14 10:54:59.252: E/AndroidRuntime(267): ... 11 more
Edit :
33rd line is
OptionsList.setAdapter(adapter);
when i try setting adapter to list it gives error if i remove this line no error is displayed and also no components on screen are displayed only a black screen appears
Thanks everybody for precious time and replys my mistake was in the menu_home_activity i added android:name="#+id/OptionsList"
that i changed to
android:id="#+id/OptionsList"
Try to put the code in try-catch block
I think
OptionsList = (ListView) findViewById(R.id.OptionsLists);
is causing a null pointer. Better handle the code for possible exceptions(null or others).
I think the below code will help you to solve your problem:
public class ArrayAdapterDemo extends ListActivity {
TextView selection;
String[] items = { "this", "is", "a", "really",
"silly", "list" };
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setListAdapter(new ArrayAdapter<String>(
this,
android.R.layout.simple_expandable_list_item_1,
items));
selection=(TextView)findViewById(R.id.selection);
}
Just replace this
adapter = new ArrayAdapter<String>(MenuHomeActivity.this,
R.layout.menu_home_activity, R.id.text, array);
in your code by
adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,array);
Problem is in 33rd Line of your java file for the concerned Activity. I guess your list view is not getting initialized properly .
your optionsList is not getting created properly, which is probably because of some problem with ure xml file. The ListView is not getting inflated properly;
try replacing match_parent with fill_parent in android:layout_width="match_parent" and android:layout_height="match_parent"
Hope this helps.

NPE when a TabActivity is started

I have an activity that is formed of 2 tabs. The problem is, when I have this code:
tabHost.setCurrentTab(0);
I am getting the following exception:
03-14 01:06:39.520: ERROR/AndroidRuntime(588): java.lang.NullPointerException
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.view.ViewRoot.handleMessage(ViewRoot.java:1819)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.os.Looper.loop(Looper.java:123)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at android.app.ActivityThread.main(ActivityThread.java:4363)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at java.lang.reflect.Method.invoke(Method.java:521)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-14 01:06:39.520: ERROR/AndroidRuntime(588): at dalvik.system.NativeStart.main(Native Method)
However, if I change the second tab to be displayed by default (I have only 2 tabs), as in:
tabHost.setCurrentTab(1);
everything is displayed correctly and I am able to switch between the tabs as well. This tells me that the tabs are configured correctly somehow, but then, why this behavior ?
I realized what I was doing wrong: the Tab mechanism was working ok, it was a ListActivity implemented for the first tab that was causing the NPE.

Categories

Resources