Email sending from android application - android

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

Related

Genymotion emulator crashes when logging in

My app crashes when trying to verify username and password from mySQL database (logging in). This is verified on an AsyncTask method. It works fine on the normal Eclipse emulator. Are there any settings or tweaks to be done? Does it crash coz of the AsyncTask, or is there any other factor?
Here's the logcat:
03-14 17:01:57.755: W/EGL_genymotion(2395): eglSurfaceAttrib not implemented
03-14 17:03:00.862: W/System.err(2395): org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2 refused
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
03-14 17:03:00.862: W/System.err(2395): at com.example.shareity.library.JSONParser.getJSONFromUrl(JSONParser.java:33)
03-14 17:03:00.862: W/System.err(2395): at com.example.shareity.library.UserFunctions.loginUser(UserFunctions.java:35)
03-14 17:03:00.862: W/System.err(2395): at com.example.shareity.Login$ProcessLogin.doInBackground(Login.java:204)
03-14 17:03:00.862: W/System.err(2395): at com.example.shareity.Login$ProcessLogin.doInBackground(Login.java:1)
03-14 17:03:00.862: W/System.err(2395): at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-14 17:03:00.862: W/System.err(2395): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-14 17:03:00.862: W/System.err(2395): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-14 17:03:00.862: W/System.err(2395): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-14 17:03:00.862: W/System.err(2395): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-14 17:03:00.862: W/System.err(2395): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-14 17:03:00.862: W/System.err(2395): at java.lang.Thread.run(Thread.java:856)
03-14 17:03:00.862: W/System.err(2395): Caused by: java.net.ConnectException: failed to connect to /10.0.2.2 (port 80): connect failed: ETIMEDOUT (Connection timed out)
03-14 17:03:00.862: W/System.err(2395): at libcore.io.IoBridge.connect(IoBridge.java:114)
03-14 17:03:00.862: W/System.err(2395): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
03-14 17:03:00.862: W/System.err(2395): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
03-14 17:03:00.862: W/System.err(2395): at java.net.Socket.connect(Socket.java:842)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
03-14 17:03:00.862: W/System.err(2395): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
03-14 17:03:00.862: W/System.err(2395): ... 17 more
03-14 17:03:00.862: W/System.err(2395): Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
03-14 17:03:00.862: W/System.err(2395): at libcore.io.Posix.connect(Native Method)
03-14 17:03:00.862: W/System.err(2395): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
03-14 17:03:00.862: W/System.err(2395): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
03-14 17:03:00.862: W/System.err(2395): at libcore.io.IoBridge.connect(IoBridge.java:112)
03-14 17:03:00.862: W/System.err(2395): ... 22 more
03-14 17:03:00.862: E/Buffer Error(2395): Error converting result java.lang.NullPointerException
03-14 17:03:00.862: E/JSON Parser(2395): Error parsing data org.json.JSONException: End of input at character 0 of
03-14 17:03:00.878: D/AndroidRuntime(2395): Shutting down VM
03-14 17:03:00.878: W/dalvikvm(2395): threadid=1: thread exiting with uncaught exception (group=0xa62d0288)
03-14 17:03:00.878: E/AndroidRuntime(2395): FATAL EXCEPTION: main
03-14 17:03:00.878: E/AndroidRuntime(2395): java.lang.NullPointerException
03-14 17:03:00.878: E/AndroidRuntime(2395): at com.example.shareity.Login$ProcessLogin.onPostExecute(Login.java:210)
03-14 17:03:00.878: E/AndroidRuntime(2395): at com.example.shareity.Login$ProcessLogin.onPostExecute(Login.java:1)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.os.AsyncTask.finish(AsyncTask.java:631)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.os.Looper.loop(Looper.java:137)
03-14 17:03:00.878: E/AndroidRuntime(2395): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-14 17:03:00.878: E/AndroidRuntime(2395): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 17:03:00.878: E/AndroidRuntime(2395): at java.lang.reflect.Method.invoke(Method.java:511)
03-14 17:03:00.878: E/AndroidRuntime(2395): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-14 17:03:00.878: E/AndroidRuntime(2395): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-14 17:03:00.878: E/AndroidRuntime(2395): at dalvik.system.NativeStart.main(Native Method)
03-14 17:08:00.935: I/Process(2395): Sending signal. PID: 2395 SIG: 9

Unable to connect with local server via android device

installed XAMPP server, created database and successfully accessed it from chrome browser as well as from android emulator. However whenever i try to run application from my Samsung device, its refusing to connect my IP address.
My IP address is not registered in DNS.
I tried:
1) accessing from url- 127.0.0.1 and localhost
2) modified httpd.conf and httpd-xampp.conf file- changed to Require all granted permission
3) uninstalled my Antivirus
4) changed firewall and proxy setting
5) Created new Inbound Rule in firewall advance security
6) re typed INTERNET permission
7) wrote httpPost.setHeader("Accept", "application/json"); in code
Still Im getting following error:
W/IInputConnectionWrapper(22232): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(22232): setComposingText on inactive InputConnection
W/IInputConnectionWrapper(22232): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(22232): setComposingText on inactive InputConnection
D/request!(22232): starting
W/System.err(22232): org.apache.http.conn.HttpHostConnectException: Connection to
http://192.XXX.X.XXX refused
W/System.err(22232): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
W/System.err(22232): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/System.err(22232): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/System.err(22232): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
W/System.err(22232): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err(22232): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err(22232): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/System.err(22232): at com.example.mysqltest.JSONParser.makeHttpRequest(JSONParser.java:111)
W/System.err(22232): at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:121)
W/System.err(22232): at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:1)
W/System.err(22232): at android.os.AsyncTask$2.call(AsyncTask.java:287)
W/System.err(22232): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
W/System.err(22232): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
W/System.err(22232): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
W/System.err(22232): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
W/System.err(22232): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
W/System.err(22232): at java.lang.Thread.run(Thread.java:856)
W/System.err(22232): Caused by: java.net.ConnectException: failed to connect to /192.168.0.114 (port 80): connect failed: ETIMEDOUT (Connection timed out)
W/System.err(22232): at libcore.io.IoBridge.connect(IoBridge.java:114)
W/System.err(22232): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
W/System.err(22232): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:460)
W/System.err(22232): at java.net.Socket.connect(Socket.java:832)
W/System.err(22232): at `enter code here`org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
W/System.err(22232): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
W/System.err(22232): ... 16 more
W/System.err(22232): Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
W/System.err(22232): at libcore.io.Posix.connect(Native Method)
W/System.err(22232): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
W/System.err(22232): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
W/System.err(22232): at libcore.io.IoBridge.connect(IoBridge.java:112)
W/System.err(22232): ... 21 more
E/Buffer Error(22232): Error converting result java.lang.NullPointerException
E/JSON Parser(22232): Error parsing data org.json.JSONException: End of input at character 0 of
W/dalvikvm(22232): threadid=12: thread exiting with uncaught exception (group=0x41180438)
E/AndroidRuntime(22232): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(22232): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(22232): at android.os.AsyncTask$3.done(AsyncTask.java:299)
E/AndroidRuntime(22232): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
E/AndroidRuntime(22232): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
E/AndroidRuntime(22232): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
E/AndroidRuntime(22232): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
E/AndroidRuntime(22232): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
E/AndroidRuntime(22232): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
E/AndroidRuntime(22232): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
E/AndroidRuntime(22232): at java.lang.Thread.run(Thread.java:856)
E/AndroidRuntime(22232): Caused by: java.lang.NullPointerException
E/AndroidRuntime(22232): at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:125)
E/AndroidRuntime(22232): at com.example.mysqltest.Login$AttemptLogin.doInBackground(Login.java:1)
E/AndroidRuntime(22232): at android.os.AsyncTask$2.call(AsyncTask.java:287)
E/AndroidRuntime(22232): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
E/AndroidRuntime(22232): ... 5 more
I/Choreographer(22232): Skipped 1143 frames! The application may be doing too much work on its main thread.
E/WindowManager(22232): Activity com.example.mysqltest.Login has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41bea8a8 that was originally added here
E/WindowManager(22232): android.view.WindowLeaked: Activity com.example.mysqltest.Login has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#41bea8a8 that was originally added here
E/WindowManager(22232): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:419)
E/WindowManager(22232): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:322)
E/WindowManager(22232): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:234)
E/WindowManager(22232): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:153)
E/WindowManager(22232): at android.view.Window$LocalWindowManager.addView(Window.java:557)
E/WindowManager(22232): at android.app.Dialog.show(Dialog.java:277)
E/WindowManager(22232): at com.example.mysqltest.Login$AttemptLogin.onPreExecute(Login.java:103)
E/WindowManager(22232): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
E/WindowManager(22232): at android.os.AsyncTask.execute(AsyncTask.java:534)
E/WindowManager(22232): at com.example.mysqltest.Login.onClick(Login.java:77)
E/WindowManager(22232): at android.view.View.performClick(View.java:4191)
E/WindowManager(22232): at android.view.View$PerformClick.run(View.java:17229)
E/WindowManager(22232): at android.os.Handler.handleCallback(Handler.java:615)
E/WindowManager(22232): at android.os.Handler.dispatchMessage(Handler.java:92)
E/WindowManager(22232): at android.os.Looper.loop(Looper.java:137)
E/WindowManager(22232): at android.app.ActivityThread.main(ActivityThread.java:4960)
E/WindowManager(22232): at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager(22232): at java.lang.reflect.Method.invoke(Method.java:511)
E/WindowManager(22232): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
E/WindowManager(22232): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
E/WindowManager(22232): at dalvik.system.NativeStart.main(Native Method)"
Please try to check your local IP address of your PC. Connect the phone to the same network (WIFI). Then use the following address/port to connect to your PC.
In Android:
URL: your_pc_local_ip
PORT: 80 (but I think it is not mandatory)
I use in this way and it is working properly for me.

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

getting position of database item from non list view view?

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.

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