Java for Android Null Pointer Exception on IInAppBillingService.getSkuDetails - java
When I run the below Java for Android code, I get a NullPointerException on the line that calls getSkuDetails in the doInBackground method in the GetItemList class. But when I step through in the debugger, all the parameters to getSkuDetails have values. pName is not an empty string and querySkus has two items in it. The exact error message I'm getting is "Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle)' on a null object reference." Does anyone know why?
package com.myknitcards;
import java.util.ArrayList;
import org.json.JSONException;
import org.json.JSONObject;
import com.android.vending.billing.IInAppBillingService;
import android.app.Activity;
import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class AvailableCards extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_available_cards);
String packagename = this.getPackageName();
TextView priceView = (TextView)findViewById(R.id.availablePrice);
new GetItemList(packagename, priceView).execute();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.available_cards, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
class GetItemList extends AsyncTask<Integer, Integer, Long> {
private String pName;
private TextView pView;
GetItemList(String packagename, TextView priceView){
pName = packagename;
pView = priceView;
}
IInAppBillingService mService;
ServiceConnection mServiceConn = new ServiceConnection() {
#Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
#Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
}
};
#Override
protected Long doInBackground(Integer... params) {
ArrayList<String> skuList = new ArrayList<String> ();
skuList.add("i001");
skuList.add("i002");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails = null;
try {
skuDetails = mService.getSkuDetails(3, pName, "inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> responseList
= skuDetails.getStringArrayList("DETAILS_LIST");
for (String thisResponse : responseList) {
JSONObject object;
object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String price = object.getString("price");
String mFirstIntermediate;
String mSecondIntermediate;
if (sku.equals("i001")) mFirstIntermediate = price;
else if (sku.equals("i002")) mSecondIntermediate = price;
pView.setText(sku + ": " + price);
}
}
} catch (NullPointerException ne) {
Log.d("Synch Billing", "Error Null Pointer: " + ne.getMessage());
ne.printStackTrace();
}
catch (RemoteException e) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error Remote: " + e.getMessage());
e.printStackTrace();
}
catch (JSONException je) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error JSON: " + je.getMessage());
je.printStackTrace();
}
return null;
}
}
Here's my log:
01-25 19:02:18.888: D/AndroidRuntime(4802): >>>>>> START com.android.internal.os.RuntimeInit uid 2000 <<<<<<
01-25 19:02:18.894: D/AndroidRuntime(4802): CheckJNI is OFF
01-25 19:02:18.951: D/ICU(4802): No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
01-25 19:02:19.016: I/Radio-JNI(4802): register_android_hardware_Radio DONE
01-25 19:02:19.048: D/AndroidRuntime(4802): Calling main entry com.android.commands.pm.Pm
01-25 19:02:19.054: I/art(4802): System.exit called, status: 0
01-25 19:02:19.055: I/AndroidRuntime(4802): VM exiting with result code 0.
01-25 19:02:19.904: D/AndroidRuntime(4816): >>>>>> START com.android.internal.os.RuntimeInit uid 2000 <<<<<<
01-25 19:02:19.911: D/AndroidRuntime(4816): CheckJNI is OFF
01-25 19:02:19.969: D/ICU(4816): No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
01-25 19:02:20.030: I/Radio-JNI(4816): register_android_hardware_Radio DONE
01-25 19:02:20.061: D/AndroidRuntime(4816): Calling main entry com.android.commands.am.Am
01-25 19:02:20.065: I/ActivityManager(607): Force stopping com.myknitcards appid=10087 user=-1: set debug app
01-25 19:02:20.066: I/ActivityManager(607): Killing 4727:com.myknitcards/u0a87 (adj 7): stop com.myknitcards
01-25 19:02:20.077: D/GraphicsStats(607): Buffer count: 3
01-25 19:02:20.077: I/WindowState(607): WIN DEATH: Window{9799d39 u0 com.myknitcards/com.myknitcards.MyKnitCardsMain}
01-25 19:02:20.179: I/ActivityManager(607): Force finishing activity ActivityRecord{16bdee6 u0 com.myknitcards/.MyKnitCardsMain t53}
01-25 19:02:20.182: W/ActivityManager(607): Spurious death for ProcessRecord{d0de1a6 0:com.myknitcards/u0a87}, curProc for 4727: null
01-25 19:02:20.183: I/ActivityManager(607): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.myknitcards/.MyKnitCardsMain} from uid 2000 on display 0
01-25 19:02:20.195: D/AndroidRuntime(4816): Shutting down VM
01-25 19:02:20.226: I/ActivityManager(607): Start proc 4826:com.myknitcards/u0a87 for activity com.myknitcards/.MyKnitCardsMain
01-25 19:02:20.233: I/art(4826): Late-enabling -Xcheck:jni
01-25 19:02:20.272: E/art(4826): Failed sending reply to debugger: Broken pipe
01-25 19:02:20.272: I/art(4826): Debugger is no longer active
01-25 19:02:20.292: W/ActivityThread(4826): Application com.myknitcards is waiting for the debugger on port 8100...
01-25 19:02:20.293: I/System.out(4826): Sending WAIT chunk
01-25 19:02:20.341: I/OpenGLRenderer(607): Initialized EGL, version 1.4
01-25 19:02:21.296: I/art(4826): Debugger is active
01-25 19:02:21.495: I/System.out(4826): Debugger has connected
01-25 19:02:21.495: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:21.695: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:21.895: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.096: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.297: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.498: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.698: I/System.out(4826): waiting for debugger to settle...
01-25 19:02:22.898: I/System.out(4826): debugger has settled (1457)
01-25 19:02:22.975: W/System(4826): ClassLoader referenced unknown path: /data/app/com.myknitcards-1/lib/arm
01-25 19:02:23.044: D/OpenGLRenderer(4826): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-25 19:02:23.076: D/Finsky(1556): [101] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:23.080: D/Finsky(1556): [143] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:23.084: D/com.myknitcards(4826): In-app Billing is set up OK
01-25 19:02:23.105: I/Adreno-EGL(4826): <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 10/21/15, 369a2ea, I96aee987eb
01-25 19:02:23.108: I/OpenGLRenderer(4826): Initialized EGL, version 1.4
01-25 19:02:23.133: W/AppOps(607): Finishing op nesting under-run: uid 1000 pkg android code 24 time=1451855407389 duration=1783 nesting=0
01-25 19:02:23.222: I/ActivityManager(607): Displayed com.myknitcards/.MyKnitCardsMain: +3s7ms
01-25 19:02:23.225: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:23.231: D/WifiStateMachine(607): starting scan for "BooNetwork-5G"WPA_PSK with 2462,5785
01-25 19:02:24.523: D/audio_hw_primary(196): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
01-25 19:02:24.524: I/ActivityManager(607): START u0 {cmp=com.myknitcards/.AvailableCards} from uid 10087 on display 0
01-25 19:02:24.533: D/audio_hw_primary(196): select_devices: out_snd_device(2: speaker) in_snd_device(0: none)
01-25 19:02:24.533: D/ACDB-LOADER(196): ACDB -> send_afe_cal
01-25 19:02:24.533: D/audio_hw_primary(196): enable_snd_device: snd_device(2: speaker)
01-25 19:02:24.542: D/audio_hw_primary(196): enable_audio_route: apply and update mixer path: low-latency-playback
01-25 19:02:24.666: I/ActivityManager(607): Displayed com.myknitcards/.AvailableCards: +134ms
01-25 19:02:24.667: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:24.719: D/OpenGLRenderer(4826): endAllStagingAnimators on 0xb388d500 (RippleDrawable) with handle 0xb36fe690
01-25 19:02:27.777: D/audio_hw_primary(196): disable_audio_route: reset and update mixer path: low-latency-playback
01-25 19:02:27.778: D/audio_hw_primary(196): disable_snd_device: snd_device(2: speaker)
01-25 19:02:31.524: D/Synch Billing(4826): Error Null Pointer: Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle)' on a null object reference
01-25 19:02:34.741: W/System.err(4826): java.lang.NullPointerException: Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getSkuDetails(int, java.lang.String, java.lang.String, android.os.Bundle)' on a null object reference
01-25 19:02:34.742: W/System.err(4826): at com.myknitcards.GetItemList.doInBackground(AvailableCards.java:87)
01-25 19:02:34.742: W/System.err(4826): at com.myknitcards.GetItemList.doInBackground(AvailableCards.java:1)
01-25 19:02:34.742: W/System.err(4826): at android.os.AsyncTask$2.call(AsyncTask.java:295)
01-25 19:02:34.743: W/System.err(4826): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-25 19:02:34.743: W/System.err(4826): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
01-25 19:02:34.743: W/System.err(4826): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
01-25 19:02:34.743: W/System.err(4826): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
01-25 19:02:34.743: W/System.err(4826): at java.lang.Thread.run(Thread.java:818)
01-25 19:02:38.949: W/art(4826): Debugger told VM to exit with status 1
01-25 19:02:39.025: D/GraphicsStats(607): Buffer count: 3
01-25 19:02:39.026: I/WindowState(607): WIN DEATH: Window{f33f18e u0 com.myknitcards/com.myknitcards.MyKnitCardsMain}
01-25 19:02:39.029: I/WindowState(607): WIN DEATH: Window{6d143a7 u0 com.myknitcards/com.myknitcards.AvailableCards}
01-25 19:02:39.047: I/Zygote(206): Process 4826 exited cleanly (1)
01-25 19:02:39.066: I/ActivityManager(607): Process com.myknitcards (pid 4826) has died
01-25 19:02:39.068: W/ActivityManager(607): Force removing ActivityRecord{d4915cb u0 com.myknitcards/.AvailableCards t54}: app died, no saved state
01-25 19:02:39.080: I/ActivityManager(607): Start proc 4874:com.myknitcards/u0a87 for activity com.myknitcards/.MyKnitCardsMain
01-25 19:02:39.100: I/art(4874): Late-enabling -Xcheck:jni
01-25 19:02:39.157: W/System(4874): ClassLoader referenced unknown path: /data/app/com.myknitcards-1/lib/arm
01-25 19:02:39.223: D/OpenGLRenderer(4874): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-25 19:02:39.264: I/Adreno-EGL(4874): <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 10/21/15, 369a2ea, I96aee987eb
01-25 19:02:39.267: I/OpenGLRenderer(4874): Initialized EGL, version 1.4
01-25 19:02:39.342: D/Finsky(1556): [100] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:39.346: D/Finsky(1556): [101] InAppBillingUtils.getPreferredAccount: com.myknitcards: Account from first account - [j5w9pVwTyqMNo_FRNWfkXIUz9SE]
01-25 19:02:39.347: D/com.myknitcards(4874): In-app Billing is set up OK
01-25 19:02:39.404: I/ActivityManager(607): Displayed com.myknitcards/.MyKnitCardsMain: +335ms
01-25 19:02:39.404: W/InputMethodManagerService(607): Got RemoteException sending setActive(false) notification to pid 4826 uid 10087
01-25 19:02:39.412: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:40.885: D/audio_hw_primary(196): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
01-25 19:02:40.888: I/ActivityManager(607): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher (has extras)} from uid 1000 on display 0
01-25 19:02:40.895: D/audio_hw_primary(196): select_devices: out_snd_device(2: speaker) in_snd_device(0: none)
01-25 19:02:40.895: D/ACDB-LOADER(196): ACDB -> send_afe_cal
01-25 19:02:40.895: D/audio_hw_primary(196): enable_snd_device: snd_device(2: speaker)
01-25 19:02:40.905: D/audio_hw_primary(196): enable_audio_route: apply and update mixer path: low-latency-playback
01-25 19:02:41.013: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:41.014: I/art(607): Background partial concurrent mark sweep GC freed 25641(1654KB) AllocSpace objects, 19(376KB) LOS objects, 33% free, 18MB/27MB, paused 2.227ms total 106.933ms
01-25 19:02:41.560: W/OpenGLRenderer(1111): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
01-25 19:02:41.560: W/OpenGLRenderer(1111): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
01-25 19:02:43.233: D/WifiStateMachine(607): starting scan for "BooNetwork-5G"WPA_PSK with 2462,5785
01-25 19:02:43.616: I/PowerManagerService(607): Going to sleep due to lid switch (uid 1000)...
01-25 19:02:43.616: I/PowerManagerService(607): Sleeping (uid 1000)...
01-25 19:02:43.621: W/AudioPolicyIntefaceImpl(196): getOutputForAttr uid 10012 tried to pass itself off as 1000
01-25 19:02:43.622: W/AudioFlinger(196): uid 10012 tried to pass itself off as 1000
01-25 19:02:43.625: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:43.632: D/audio_hw_primary(196): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
01-25 19:02:43.698: I/ActivityManager(607): Config changes=480 {1.0 310mcc?mnc en_US ldltr sw600dp w960dp h528dp 320dpi lrg land finger -keyb/v/h -nav/h s.6}
01-25 19:02:43.700: I/InputReader(607): Reconfiguring input devices. changes=0x00000004
01-25 19:02:43.700: I/InputReader(607): Device reconfigured: id=6, name='elan-touchscreen', size 1200x1920, orientation 1, mode 1, display id 0
01-25 19:02:43.703: V/AudioService.RotationHelper(607): publishing device rotation =1 (x90deg)
01-25 19:02:43.707: D/audio_hw_primary(196): adev_set_parameters: enter: rotation=90
01-25 19:02:44.040: D/Launcher.Model(1111): DbDebug Modify item (Play Music) in db, id: 4 (2, 0, 0, 0) --> (2, 0, 0, 0)
01-25 19:02:44.040: D/Launcher.Model(1111): DbDebug Modify item (Play Books) in db, id: 6 (2, 0, 1, 0) --> (2, 0, 1, 0)
01-25 19:02:44.041: D/Launcher.Model(1111): DbDebug Modify item (Play Movies & TV) in db, id: 8 (2, 0, 2, 0) --> (2, 0, 2, 0)
01-25 19:02:44.041: D/Launcher.Model(1111): DbDebug Modify item (Play Games) in db, id: 10 (2, 0, 3, 0) --> (2, 0, 3, 0)
01-25 19:02:44.042: D/Launcher.Model(1111): DbDebug Modify item (Play Newsstand) in db, id: 12 (2, 0, 0, 1) --> (2, 0, 0, 1)
01-25 19:02:44.042: D/Launcher.Model(1111): DbDebug Modify item (Google+) in db, id: 14 (2, 0, 1, 1) --> (2, 0, 1, 1)
01-25 19:02:44.043: D/Launcher.Model(1111): DbDebug Modify item (Keep) in db, id: 16 (2, 0, 2, 1) --> (2, 0, 2, 1)
01-25 19:02:44.043: D/Launcher.Model(1111): DbDebug Modify item (Calendar) in db, id: 20 (2, 0, 3, 1) --> (2, 0, 3, 1)
01-25 19:02:44.043: D/Launcher.Model(1111): DbDebug Modify item (Currents) in db, id: 22 (2, 0, 0, 2) --> (2, 0, 0, 2)
01-25 19:02:44.044: D/Launcher.Model(1111): DbDebug Modify item (Photos) in db, id: 24 (2, 0, 1, 2) --> (2, 0, 1, 2)
01-25 19:02:44.044: D/Launcher.Model(1111): DbDebug Modify item (Earth) in db, id: 26 (2, 0, 2, 2) --> (2, 0, 2, 2)
01-25 19:02:44.147: I/Keyboard.Facilitator(1004): onFinishInput()
01-25 19:02:44.190: I/Launcher(1111): Deferring update until onResume
01-25 19:02:44.191: I/Launcher(1111): Deferring update until onResume
01-25 19:02:44.202: I/WindowManager(607): Screen frozen for +551ms due to Window{b92ff9b u0 com.android.launcher/com.android.launcher2.Launcher}
01-25 19:02:44.222: V/KeyguardServiceDelegate(607): onScreenTurnedOff()
01-25 19:02:44.249: I/DisplayManagerService(607): Display device changed state: "Built-in Screen", OFF
01-25 19:02:44.249: D/SurfaceFlinger(188): Set power mode=0, type=0 flinger=0xb6aa4000
01-25 19:02:44.529: D/SurfaceControl(607): Excessive delay in setPowerMode(): 280ms
01-25 19:02:44.530: E/ANDR-PERF-LOCK(204): Failed to apply optimization for resource: 4 level: 0
01-25 19:02:44.540: D/audio_hw_primary(196): adev_set_parameters: enter: screen_state=off
01-25 19:02:44.545: W/qcom_sensors_hal(607): hal_acquire_resources, no active sensors!
01-25 19:02:44.554: E/native(607): do suspend true
01-25 19:02:44.580: D/PhoneStatusBar(705): disable: < expand ICONS* alerts SYSTEM_INFO* back home recent clock search quick_settings >
01-25 19:02:44.721: D/PhoneStatusBar(705): disable: < expand ICONS alerts SYSTEM_INFO back HOME* RECENT* clock SEARCH* quick_settings >
01-25 19:02:46.209: I/art(607): Starting a blocking GC Explicit
01-25 19:02:46.280: I/art(607): Explicit concurrent mark sweep GC freed 14241(923KB) AllocSpace objects, 8(160KB) LOS objects, 33% free, 17MB/26MB, paused 1.129ms total 70.343ms
01-25 19:02:46.953: D/audio_hw_primary(196): disable_audio_route: reset and update mixer path: low-latency-playback
01-25 19:02:46.953: D/audio_hw_primary(196): disable_snd_device: snd_device(2: speaker)
01-25 19:03:03.251: D/WifiStateMachine(607): L2Connected CMD_START_SCAN source -2 41, 42 -> obsolete
01-25 19:03:03.787: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:03:14.835: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:03:29.947: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:03:41.038: E/(193): invalid crash request of size 4 (from pid=4794 uid=0)
01-25 19:03:41.165: E/Diag_Lib(4962): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:03:41.166: E/Sensors(4962): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:03:41.166: E/Sensors(4962): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:03:41.198: W/Sensors(4962): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6f34a08
01-25 19:03:41.261: W/Sensors(4962): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:03:41.272: E/Sensors(4962): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:03:44.187: I/Keyboard.Facilitator.LanguageModelFlusher(1004): run()
01-25 19:03:44.188: I/Keyboard.Facilitator(1004): flushDynamicLanguageModels()
01-25 19:03:44.237: I/ConfigService(1203): onCreate
01-25 19:03:49.340: I/ConfigService(1203): onDestroy
01-25 19:03:54.819: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:04:09.828: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:04:57.794: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:05:12.826: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:05:13.472: E/(193): invalid crash request of size 4 (from pid=4962 uid=0)
01-25 19:05:13.615: E/Diag_Lib(4977): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:05:13.615: E/Sensors(4977): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:05:13.616: E/Sensors(4977): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:05:13.648: W/Sensors(4977): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6fc4a08
01-25 19:05:13.713: W/Sensors(4977): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:05:13.726: E/Sensors(4977): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:06:00.771: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:06:15.788: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:06:45.928: E/(193): invalid crash request of size 4 (from pid=4977 uid=0)
01-25 19:06:46.091: E/Diag_Lib(4991): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:06:46.091: E/Sensors(4991): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:06:46.092: E/Sensors(4991): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:06:46.119: W/Sensors(4991): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6f2ea08
01-25 19:06:46.185: W/Sensors(4991): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:06:46.200: E/Sensors(4991): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:07:00.446: I/UsageStatsService(607): User[0] Flushing usage stats to disk
01-25 19:07:06.820: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:07:21.828: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:08:09.795: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:08:18.400: E/(193): invalid crash request of size 4 (from pid=4991 uid=0)
01-25 19:08:18.715: E/Diag_Lib(5008): Diag_LSM_Init: Failed to open handle to diag driver, error = 2
01-25 19:08:18.717: E/Sensors(5008): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:08:18.718: E/Sensors(5008): sns_fsa_la.c(386):fsa: fflush failed, 9
01-25 19:08:18.748: W/Sensors(5008): sns_smr_la.c(446):smr_la: smr_apps_la_thread_main is starting, fd=11, sns_smr.en_rx_msg_ptr=b6ffca08
01-25 19:08:18.808: W/Sensors(5008): sns_sam_app.c(6827):sns_sam_reg_algo: Registering algo service 16, err 0
01-25 19:08:18.819: E/Sensors(5008): sns_debug_main.c(565):Debug Config File missing in EFS!
01-25 19:08:24.828: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
01-25 19:09:12.771: E/NetlinkEvent(192): NetlinkEvent::FindParam(): Parameter 'UID' not found
What could probably be happening is that mServiceConn instance of ServiceConnection connection class takes some time to connect, and until the connection is established, mService remains null.
To fix this, please try the following code:
public class AvailableCards extends Activity {
IInAppBillingService mService;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_available_cards);
String packagename = this.getPackageName();
TextView priceView = (TextView)findViewById(R.id.availablePrice);
ServiceConnection mServiceConn = new ServiceConnection() {
#Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
#Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
new GetItemList(packagename, priceView).execute();
}
};
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.available_cards, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
class GetItemList extends AsyncTask<Integer, Integer, Long> {
private String pName;
private TextView pView;
GetItemList(String packagename, TextView priceView){
pName = packagename;
pView = priceView;
}
#Override
protected Long doInBackground(Integer... params) {
ArrayList<String> skuList = new ArrayList<String> ();
skuList.add("i001");
skuList.add("i002");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails = null;
try {
skuDetails = mService.getSkuDetails(3, pName, "inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> responseList
= skuDetails.getStringArrayList("DETAILS_LIST");
for (String thisResponse : responseList) {
JSONObject object;
object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String price = object.getString("price");
String mFirstIntermediate;
String mSecondIntermediate;
if (sku.equals("i001")) mFirstIntermediate = price;
else if (sku.equals("i002")) mSecondIntermediate = price;
pView.setText(sku + ": " + price);
}
}
} catch (NullPointerException ne) {
Log.d("Synch Billing", "Error Null Pointer: " + ne.getMessage());
ne.printStackTrace();
}
catch (RemoteException e) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error Remote: " + e.getMessage());
e.printStackTrace();
}
catch (JSONException je) {
// TODO Auto-generated catch block
Log.d("Synch Billing", "Error JSON: " + je.getMessage());
je.printStackTrace();
}
return null;
}
}
Related
Use date to manage subscriptions. Android. Firebase
My problem is with this activity. I want to get the time, compare it to the time on the database, and then if the subscription hasnt expired show a button, if it has hide it. Plus i want to show the credits a user has, and image and his name on top. I have tried many things, but it keeps crashing for some reason. public void getthedate(){ calendar = Calendar.getInstance(); final SimpleDateFormat mdformat = new SimpleDateFormat("yyyy / MM / dd "); // strDate = "Current Date : " + mdformat.format(calendar.getTime()); // futurecal = Calendar.getInstance(); // futurecal.add(Calendar.DATE, 30); // futuredate = mdformat.format(futurecal.getTime()); DatabaseReference subtime = mDatabase.child("users").child(univ).child(uid); subtime.addListenerForSingleValueEvent(new ValueEventListener() { #Override public void onDataChange(#NonNull DataSnapshot dataSnapshot) { subtimedate = dataSnapshot.child("subdate").getValue().toString(); String username = dataSnapshot.child("Full name").getValue().toString(); String coinstring = dataSnapshot.child("coins").getValue().toString(); coinview.setText(coinstring); String imglink = dataSnapshot.child("imageuri").getValue().toString(); Glide.with(c).load(imglink).into(userthing); hellostring.setText("Hey" + username + "!"); Date subdatecal = null; try { subdatecal = mdformat.parse(subtimedate); } catch (ParseException e) { e.printStackTrace(); } Calendar newestcal = Calendar.getInstance(); newestcal.setTime(subdatecal); if (newestcal.after(mdformat.format(calendar.getTime()))){ substat.setText("Active"); substat.setBackgroundColor(Color.GREEN); //do something if subscription hasnt expired }else{ gotonotes.setVisibility(View.GONE); substat.setText("Expired"); substat.setBackgroundColor(Color.RED); } } #Override public void onCancelled(#NonNull DatabaseError databaseError) { } }); /* DatabaseReference subtime = mDatabase.child("users").child(univ).child(uid).child("subdate"); subtime.setValue(futuredate); set new subscription */ /* if (calendar.after(futurecal)){ use this to check if date has passed }*/ } In the oncreate i have setup everything. substat = (TextView) findViewById(R.id.substat); hellostring = (TextView) findViewById(R.id.hellostring); coinview = (TextView) findViewById(R.id.coinview); userthing = (ImageView) findViewById(R.id.userimagething); mDatabase = FirebaseDatabase.getInstance().getReference(); friendbtn = (Button) findViewById(R.id.friendsbtn); uid = FirebaseAuth.getInstance().getCurrentUser().getUid(); Thanks for any suggestions! this is logcat from my phone on android studio when the activity crashes 10-22 19:00:46.363 20227-20227/? I/art: Late-enabling -Xcheck:jni 10-22 19:00:46.473 20227-20227/com.studybuddy.mixal.android W/System: ClassLoader referenced unknown path: /data/app/com.studybuddy.mixal.android-2/lib/arm64 10-22 19:00:46.592 20227-20227/com.studybuddy.mixal.android I/FirebaseInitProvider: FirebaseApp initialization successful 10-22 19:00:46.635 20227-20227/com.studybuddy.mixal.android W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 10-22 19:00:46.639 20227-20261/com.studybuddy.mixal.android I/FA: App measurement is starting up, version: 12780 To enable debug logging run: adb shell setprop log.tag.FA VERBOSE To enable faster debug mode event logging run: adb shell setprop debug.firebase.analytics.app com.studybuddy.mixal.android 10-22 19:00:46.703 20227-20261/com.studybuddy.mixal.android I/FA: Tag Manager is not found and thus will not be used 10-22 19:00:46.705 20227-20227/com.studybuddy.mixal.android I/HwSecImmHelper: mSecurityInputMethodService is null 10-22 19:00:46.718 20227-20227/com.studybuddy.mixal.android E/HAL: load: id=gralloc != hmi->id=gralloc 10-22 19:00:46.899 20227-20284/com.studybuddy.mixal.android I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6 Selected remote version of com.google.android.gms.firebase_database, version >= 6 10-22 19:00:46.949 20227-20284/com.studybuddy.mixal.android W/System: ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000086/n/arm64-v8a 10-22 19:00:46.960 20227-20272/com.studybuddy.mixal.android E/HAL: load: id=gralloc != hmi->id=gralloc 10-22 19:00:46.961 20227-20272/com.studybuddy.mixal.android I/OpenGLRenderer: Initialized EGL, version 1.4 10-22 19:00:46.971 20227-20272/com.studybuddy.mixal.android W/OpenGLRenderer: load: so=/system/lib64/libhwuibp.so dlopen failed: library "/system/lib64/libhwuibp.so" not found Initialize Binary Program Cache: Load Failed 10-22 19:00:46.971 20227-20272/com.studybuddy.mixal.android E/HAL: load: id=gralloc != hmi->id=gralloc 10-22 19:00:47.058 20227-20299/com.studybuddy.mixal.android I/System: core_booster, getBoosterConfig = false 10-22 19:00:48.781 20227-20227/com.studybuddy.mixal.android I/Process: Sending signal. PID: 20227 SIG: 9
MediaPlayer music Android Studio
Just wanted to see if anyone could help me out or point me in the right direction. I'm learning how to make a simple music player where the user clicks on list view items and it streams the mp3. There's a play button up top and next and previous song buttons (haven't added seek functionality yet). However it keeps crashing when I select new song. Here's my activity code: public class AudioActivity extends AppCompatActivity { ListView listView; ArrayList<String> musicList; ArrayAdapter adapter; MediaPlayer player; ImageButton prev; ImageButton play; ImageButton next; #Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_audio); prev = (ImageButton) findViewById(R.id.previous); play = (ImageButton) findViewById(R.id.play); next = (ImageButton) findViewById(R.id.next); listView = findViewById(R.id.musiclist); musicList = new ArrayList<>(); musicList.add("song"); musicList.add("song1"); musicList.add("song2"); musicList.add("song3"); musicList.add("song4"); adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, musicList); listView.setAdapter(adapter); player = new MediaPlayer(); player.setAudioStreamType(AudioManager.STREAM_MUSIC); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { #Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position){ case 0: String url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"; try { player.stop(); //player.release(); player.setDataSource(url); } catch (IOException e) { e.printStackTrace(); } try { player.prepare(); } catch (IOException e) { e.printStackTrace(); } break; case 1: url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-8.mp3"; try { player.stop(); //player.release(); player.setDataSource(url); } catch (IOException e) { e.printStackTrace(); } try { player.prepare(); } catch (IOException e) { e.printStackTrace(); } break; default: break; } player.start(); } }); } public void onPlayBtnClicked(){ if(!player.isPlaying()) { player.start(); }else { player.pause(); } } } 04/05 00:08:09: Launching app $ adb shell am start -n "com.example.brads.group08/com.example.brads.group08.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D Waiting for application to come online: com.example.brads.group08.test | com.example.brads.group08 Waiting for application to come online: com.example.brads.group08.test | com.example.brads.group08 Waiting for application to come online: com.example.brads.group08.test | com.example.brads.group08 Connecting to com.example.brads.group08 Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page. W/ActivityThread: Application com.example.brads.group08 is waiting for the debugger on port 8100... I/System.out: Sending WAIT chunk I/zygote: Debugger is active Connected to the target VM, address: 'localhost:8600', transport: 'socket' I/System.out: Debugger has connected I/System.out: waiting for debugger to settle... I/System.out: waiting for debugger to settle... I/chatty: uid=10091(com.example.brads.group08) identical 4 lines I/System.out: waiting for debugger to settle... I/System.out: debugger has settled (1448) I/InstantRun: starting instant run server: is main process D/OpenGLRenderer: HWUI GL Pipeline [ 04-05 04:08:16.176 10444:10464 D/ ] HostConnection::get() New Host Connection established 0xa5a26b40, tid 10464 I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0 I/OpenGLRenderer: Initialized EGL, version 1.4 D/OpenGLRenderer: Swap behavior 1 D/EGL_emulation: eglCreateContext: 0xa5a70f60: maj 2 min 0 rcv 2 D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680) D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680) I/zygote: Do partial code cache collection, code=21KB, data=30KB I/zygote: After code cache collection, code=21KB, data=30KB I/zygote: Increasing code cache capacity to 128KB I/zygote: Do partial code cache collection, code=31KB, data=56KB I/zygote: After code cache collection, code=31KB, data=56KB I/zygote: Increasing code cache capacity to 256KB I/zygote: JIT allocated 71KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int) I/zygote: Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int) I/zygote: Do full code cache collection, code=116KB, data=72KB I/zygote: After code cache collection, code=90KB, data=45KB D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680) D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680) D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680) W/MediaPlayer: Use of stream types is deprecated for operations other than volume control W/MediaPlayer: See the documentation of setAudioStreamType() for what to use instead with android.media.AudioAttributes to qualify your playback use case D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680) D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680) D/EGL_emulation: eglMakeCurrent: 0xa5a70f60: ver 2 0 (tinfo 0xa83b2680) E/MediaPlayerNative: stop called in state 1, mPlayer(0x0) E/MediaPlayerNative: error (-38, 0) V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService#89d8a5e): Cookies: null V/MediaHTTPService: makeHTTPConnection: CookieManager created: java.net.CookieManager#a4007a4 V/MediaHTTPService: makeHTTPConnection(android.media.MediaHTTPService#89d8a5e): cookieHandler: java.net.CookieManager#a4007a4 Cookies: null D/NetworkSecurityConfig: No Network Security Config specified, using platform default I/Choreographer: Skipped 163 frames! The application may be doing too much work on its main thread. E/MediaPlayer: Error (-38,0) I/zygote: Do partial code cache collection, code=123KB, data=81KB I/zygote: After code cache collection, code=123KB, data=81KB I/zygote: Increasing code cache capacity to 512KB V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService#7615caf): Cookies: null E/MediaPlayerNative: attachNewPlayer called in state 64 E/InputEventReceiver: Exception dispatching input event. E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback E/MessageQueue-JNI: java.lang.IllegalStateException at android.media.MediaPlayer.nativeSetDataSource(Native Method) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1172) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1160) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1127) at com.example.brads.group08.AudioActivity$1.onItemClick(AudioActivity.java:65) at android.widget.AdapterView.performItemClick(AdapterView.java:318) at android.widget.AbsListView.performItemClick(AbsListView.java:1158) at android.widget.AbsListView$PerformClick.run(AbsListView.java:3127) at android.widget.AbsListView.onTouchUp(AbsListView.java:4054) at android.widget.AbsListView.onTouchEvent(AbsListView.java:3813) at android.view.View.dispatchTouchEvent(View.java:11776) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2962) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2643) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:448) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1829) at android.app.Activity.dispatchTouchEvent(Activity.java:3307) at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:410) at android.view.View.dispatchPointerEvent(View.java:12015) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4795) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4609) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4293) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4350) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6661) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6635) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6596) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6764) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:325) at android.os.Looper.loop(Looper.java:142) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.brads.group08, PID: 10444 java.lang.IllegalStateException at android.media.MediaPlayer.nativeSetDataSource(Native Method) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1172) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1160) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1127) at com.example.brads.group08.AudioActivity$1.onItemClick(AudioActivity.java:65) at android.widget.AdapterView.performItemClick(AdapterView.java:318) at android.widget.AbsListView.performItemClick(AbsListView.java:1158) at android.widget.AbsListView$PerformClick.run(AbsListView.java:3127) at android.widget.AbsListView.onTouchUp(AbsListView.java:4054) at android.widget.AbsListView.onTouchEvent(AbsListView.java:3813) at android.view.View.dispatchTouchEvent(View.java:11776) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2962) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2643) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:448) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1829) at android.app.Activity.dispatchTouchEvent(Activity.java:3307) at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:410) at android.view.View.dispatchPointerEvent(View.java:12015) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4795) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4609) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4293) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4350) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6661) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6635) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6596) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6764) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:325) at android.os.Looper.loop(Looper.java:142) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'
Unexpected status line while getting response from server on android app
I am establishing server-client communication between Android app and ESP8266 NodeMCU-1.0. The ESP is creating server on specified network and the mobile is connecting to same network. For testing purpose I am sending "try123" string when the send button is pressed. And receiving appropriate response on the serial monitor of IDE (i.e. data is received on server). But the server response which is "Test_successful" string. I am sending this string to client using client.print. In app I am toasting the server response. The problem is that if I am making the HTTP request using browser using the locally generated URL, then the response "Test_successful" is visible. But In app toast it's showing empty and while debugging it's showing error Unexpected line status. ESP code (server side): #include <ESP8266WiFi.h> const char* ssid = "DARSHAN95"; const char* password = "12345678"; //const char* ssid = "TP-LINK_42C148"; //const char* password = ""; // Create an instance of the server // specify the port to listen on as an argument WiFiServer server(80); void setup() { Serial.begin(115200); delay(10); // Connect to WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); // Start the server server.begin(); Serial.println("Server started"); // Print the IP address Serial.println(WiFi.localIP()); } void loop() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Wait until the client sends some data Serial.println("new client"); while(!client.available()){ delay(1); } // Read the first line of the request String req = client.readStringUntil('\r'); Serial.println(req); client.flush(); // Match the request //client.flush(); delay(100); // Send the response to the client client.print("Test_Sucessfull"); delay(200); Serial.println("Client disonnected"); } Android App code: Please ignore the text input block on the and its code. package com.example.access.test123; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; public class MainActivity extends AppCompatActivity { EditText Message; Button Send; String data; HttpURLConnection http; String sendingMessage; #Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Message = (EditText) findViewById(R.id.message); Send = (Button) findViewById(R.id.send); Send.setOnClickListener(new Button.OnClickListener() { #Override public void onClick(View v) { HttpAsync task = new HttpAsync(); task.execute(); } }); } public void sendDataMethod() throws UnsupportedEncodingException{ sendingMessage = Message.getText().toString(); String data = "Error"; BufferedReader reader = null; //Sending Data try{ String ip = "http://192.168.43.76/?try123"; //String address = ip + sendingMessage; //URL url = new URL(address); URL url = new URL(ip); URLConnection conn = url.openConnection(); http = (HttpURLConnection)conn; http.setRequestMethod("POST"); // PUT is another valid option http.setDoOutput(true); http.setDoInput(true); //Server Response int i = http.getResponseCode(); reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line = null; while((line = reader.readLine()) != null){ sb.append(line + "\n"); } data = sb.toString(); } catch(IOException e){; Log.d("Error2", e.toString()); } finally { try{ if(reader != null) { reader.close(); } } catch (IOException ex){ Log.d("Error3", ex.toString()); } } } private class HttpAsync extends AsyncTask { #Override protected void onPreExecute() { super.onPreExecute(); } #Override protected Object doInBackground(Object[] objects) { try { sendDataMethod(); } catch (UnsupportedEncodingException e) { Log.d("Error", e.toString()); } return null; } #Override protected void onPostExecute(Object o) { super.onPostExecute(o); Toast.makeText(MainActivity.this, data, Toast.LENGTH_SHORT).show(); } } } Debugging results: 02/07 22:40:23: Launching app $ adb install-multiple -r -t A:\New folder\Test123\app\build\intermediates\split-apk\debug\dep\dependencies.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_1.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_2.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_3.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_6.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_9.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_8.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_7.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_4.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_5.apk A:\New folder\Test123\app\build\intermediates\split-apk\debug\slices\slice_0.apk A:\New folder\Test123\app\build\outputs\apk\debug\app-debug.apk Split APKs installed $ adb shell am start -n "com.example.access.test123/com.example.access.test123.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D Waiting for application to come online: com.example.access.test123.test | com.example.access.test123 Waiting for application to come online: com.example.access.test123.test | com.example.access.test123 Waiting for application to come online: com.example.access.test123.test | com.example.access.test123 Waiting for application to come online: com.example.access.test123.test | com.example.access.test123 Waiting for application to come online: com.example.access.test123.test | com.example.access.test123 Connecting to com.example.access.test123 Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page. I/art: Debugger is active I/System.out: Debugger has connected I/System.out: waiting for debugger to settle... Connected to the target VM, address: 'localhost:8601', transport: 'socket' I/System.out: waiting for debugger to settle... I/System.out: waiting for debugger to settle... I/System.out: waiting for debugger to settle... I/System.out: waiting for debugger to settle... I/System.out: waiting for debugger to settle... I/System.out: waiting for debugger to settle... I/System.out: waiting for debugger to settle... I/System.out: debugger has settled (1436) W/System: ClassLoader referenced unknown path: /data/app/com.example.access.test123-2/lib/arm64 I/art: Starting a blocking GC HeapTrim I/InstantRun: starting instant run server: is main process I/art: Starting a blocking GC Instrumentation W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = null, this = DecorView#3280086[] D/WindowClient: Add to mViews: DecorView#3280086[MainActivity], this = android.view.WindowManagerGlobal#d5cc9ee D/OpenGLRenderer: Dumper init 4 threads <0x7c6a19ee40> D/OpenGLRenderer: <com.example.access.test123> is running. D/OpenGLRenderer: CanvasContext() 0x7c6773f880 D/ViewRootImpl[MainActivity]: hardware acceleration is enabled, this = ViewRoot{500151c com.example.access.test123/com.example.access.test123.MainActivity,ident = 0} V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = ViewRoot{500151c com.example.access.test123/com.example.access.test123.MainActivity,ident = 0}, this = DecorView#3280086[MainActivity] D/OpenGLRenderer: CanvasContext() 0x7c6773f880 initialize window=0x7c73e55e00, title=com.example.access.test123/com.example.access.test123.MainActivity D/Surface: Surface::allocateBuffers(this=0x7c73e55e00) I/OpenGLRenderer: Initialized EGL, version 1.4 D/OpenGLRenderer: Swap behavior 1 D/OpenGLRenderer: Created EGL context (0x7c6a19f600) D/OpenGLRenderer: ProgramCache.init: enable enhancement 1 I/OpenGLRenderer: Get disable program binary service property (0) I/OpenGLRenderer: Initializing program atlas... I/ProgramBinary/Service: ProgramBinaryService client side disable debugging. I/ProgramBinary/Service: ProgramBinaryService client side disable binary content debugging. D/ProgramBinary/Service: BpProgramBinaryService.getReady D/ProgramBinary/Service: BpProgramBinaryService.getProgramBinaryData I/OpenGLRenderer: Program binary detail: Binary length is 249276, program map length is 124. I/OpenGLRenderer: Succeeded to mmap program binaries. File descriptor is 74, and path is /dev/ashmem. I/OpenGLRenderer: No need to use file discriptor anymore, close fd(74). D/OpenGLRenderer: Initializing program cache from 0x0, size = -1 D/MALI: eglCreateImageKHR:513: [Crop] 0 0 896 1344 img[896 1344] D/Surface: Surface::connect(this=0x7c73e55e00,api=1) W/libEGL: [ANDROID_RECORDABLE] format: 1 D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000 W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView D/OpenGLRenderer: CacheTexture 3 upload: x, y, width height = 0, 0, 189, 441 D/OpenGLRenderer: ProgramCache.generateProgram: 0 D/OpenGLRenderer: ProgramCache.generateProgram: 34359738371 D/OpenGLRenderer: ProgramCache.generateProgram: 5242945 D/OpenGLRenderer: ProgramCache.generateProgram: 5242944 D/OpenGLRenderer: ProgramCache.generateProgram: 240518168576 D/OpenGLRenderer: ProgramCache.generateProgram: 68724719680 V/InputMethodManager: onWindowFocus: android.support.v7.widget.AppCompatEditText{8687c92 VFED..CL. .F....ID 228,66-851,212 #7f070042 app:id/message} softInputMode=288 first=true flags=#81810100 D/OpenGLRenderer: ProgramCache.generateProgram: 103084458052 D/NetworkSecurityConfig: No Network Security Config specified, using platform default I/System.out: [socket][0] connection /192.168.43.76:80;LocalPort=-1(0) [ 02-07 22:40:39.251 29396:29665 D/ ] [Posix_connect Debug]Process com.example.access.test123 :80 I/System.out: [socket][/192.168.43.1:49348] connected I/System.out: [OkHttp] sendRequest>> I/System.out: [OkHttp] sendRequest<< D/Error2: java.net.ProtocolException: Unexpected status line: Test_Sucessfull D/WindowClient: Add to mViews: android.widget.LinearLayout{3957537 V.E...... ......I. 0,0-0,0}, this = android.view.WindowManagerGlobal#d5cc9ee D/OpenGLRenderer: CanvasContext() 0x7c56092d40 D/ViewRootImpl[Toast]: hardware acceleration is enabled, this = ViewRoot{f7a400d Toast,ident = 1} D/Surface: Surface::allocateBuffers(this=0x7c58339e00) D/OpenGLRenderer: CanvasContext() 0x7c56092d40 initialize window=0x7c58339e00, title=Toast D/Surface: Surface::connect(this=0x7c58339e00,api=1) W/libEGL: [ANDROID_RECORDABLE] format: 1 D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000 D/OpenGLRenderer: ProgramCache.generateProgram: 1 D/Surface: Surface::disconnect(this=0x7c58339e00,api=1) D/Surface: Surface::disconnect(this=0x7c58339e00,api=1) D/WindowClient: Remove from mViews: android.widget.LinearLayout{3957537 V.E...... ......ID 0,0-156,140}, this = android.view.WindowManagerGlobal#d5cc9ee I/art: Do partial code cache collection, code=28KB, data=28KB I/art: After code cache collection, code=27KB, data=28KB I/art: Increasing code cache capacity to 128KB Note: At D/Error2: java.net.ProtocolException: Unexpected status line: Test_Sucessfull The string is received but with above error. Results: IDE monitor displaying data sent from client i.e. app
Finally Found the solution, the error was with the syntax of the response packet sent from ESP side so just replaced client.print("Test_Successfull"); with client.print("HTTP/1.1 200 OK\r\nConnection: Closed\r\n\r\nTest_Successful");
Intent is not starting a new Activity
public void onClick(View v) { Toast.makeText(MainActivity.this,"You taped!",Toast.LENGTH_SHORT).show(); try { startActivity(new Intent(MainActivity.this, FuelChoiceActivity.class)); }catch (Exception e){ System.out.println(e); } } Here is my code. I've added the new activity to my manifest.xml. The try/catch block is not returning any exeption. When i press the button the toast is executed and displayed but the page is not changing. This onClickListener is inside an adapter method 'getView'so it can be obtained by any button generated from the adapter. I tried putting other events and they work! The only thing that doesn't is going to the new Activity. here is my log when i debug and click on a button: D/AbsListView: reportScrollStateChange: newState = 0, mLastScrollState = 0, mOnScrollListener = null, mScrollY = 0, mTouchMode = -1, mFirstPosition = 0 V/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0 D/ActivityThread: ACT-AM_ON_PAUSE_CALLED ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} D/ActivityThread: ACT-PAUSE_ACTIVITY handled : 1 / android.os.BinderProxy#32487069 D/AbsListView: onWindowFocusChanged: hasWindowFocus=false, this=com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview} D/OpenGLRenderer: Flushing caches (mode 0) D/GraphicBuffer: register, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02) I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0 I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1 I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3 D/GraphicBuffer: unregister, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02) D/GraphicBuffer: register, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02) V/ActivityThread: Handling launch of ActivityRecord{1ff7b407 token=android.os.BinderProxy#19bbf934 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}} V/ActivityThread: ActivityRecord{1ff7b407 token=android.os.BinderProxy#19bbf934 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}}: app=android.app.Application#a0dbe1c, appName=com.example.stamatis.redhotpepper, pkg=com.example.stamatis.redhotpepper, comp={com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}, dir=/data/app/com.example.stamatis.redhotpepper-1/base.apk D/ActivityThread: ACT-LAUNCH_ACTIVITY handled : 0 / ActivityRecord{1ff7b407 token=android.os.BinderProxy#19bbf934 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.FuelChoiceActivity}} D/ActivityThread: ACT-PAUSE_ACTIVITY_FINISHING handled : 0 / android.os.BinderProxy#19bbf934 V/ActivityThread: Performing resume of ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} D/ActivityThread: ACT-AM_ON_RESUME_CALLED ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} V/ActivityThread: Resume ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} started activity: false, hideForNow: false, finished: false V/ActivityThread: Resuming ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} with isForward=true V/PhoneWindow: DecorView setVisiblity: visibility = 0 ,Parent =ViewRoot{dfe4562 com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity,ident = 0}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{1d6eaa25 V.E..... R.....I. 0,0-480,782} V/ActivityThread: Scheduling idle handler for ActivityRecord{2c1d62f0 token=android.os.BinderProxy#32487069 {com.example.stamatis.redhotpepper/com.example.stamatis.redhotpepper.MainActivity}} D/ActivityThread: ACT-RESUME_ACTIVITY handled : 1 / android.os.BinderProxy#32487069 D/AbsListView: onWindowFocusChanged: hasWindowFocus=true, this=com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview} V/InputMethodManager: onWindowFocus: com.example.stamatis.redhotpepper.ExpandableHeightGridView{1dffd375 VFED.VC. .F...... 8,0-472,965 #7f0c0053 app:id/mygridview} softInputMode=272 first=false flags=#1810100 D/ActivityThread: ACT-DESTROY_ACTIVITY handled : 1 / android.os.BinderProxy#19bbf934 D/OpenGLRenderer: Flushing caches (mode 0) D/OpenGLRenderer: Flushing caches (mode 0) D/GraphicBuffer: unregister, handle(0xb884d518) (w:177 h:66 s:192 f:0x1 u:0x000f02) Thanks for reading and your time. I would appreciate thoughts.
My main activity extends Activity public class MainActivity extends Activity In this activity i was trying to to move to another that it was extending AppCombatActivity class. public class FuelChoiceActivity extends AppCombatActivity so the syntax and all is right. So i changed the FuelChoiceActivity(the activity i desired to move at) extend to : public class FuelChoiceActivity extends Activity Seems like you cannot move to another activity if they both dont extend the same class.
Any solutions to this error?
01-25 23:51:14.507: WARN/System.err(616): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2 I have an android application that would use an SQLite database. But when it gets to the select statement it force closes. I have a class file that I use for doing this : package com.thesis.menubook; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; import java.util.ArrayList; import java.util.List; public class DBConnect { int id = 0; public static final String KEY_ROWID = "_id"; public static final String KEY_IP = "saved_ip_address"; private static final String TAG = "DBConnect"; private static final String DATABASE_NAME = "MenuBook"; private static final String DATABASE_TABLE_1 = "ipaddress"; //private static final String DATABASE_TABLE_2 = "menudb"; //private static final String DATABASE_TABLE_3 = "recipelist"; private static final int DATABASE_VERSION = 1; private static final String DATABASE_CREATE_TABLE_1 = "CREATE TABLE ipaddress (_id integer primary key autoincrement, " + "saved_ip_address text not null " + "); "; private static final String DATABASE_CREATE_TABLE_2 = "CREATE TABLE menudb (menu_ID varchar primary key not null, " + "menu_name longtext, " + "menu_price double null default, " + "menu_description longtext, " + "menu_category text, " + "menu_status text " + "); "; private static final String DATABASE_CREATE_TABLE_3 = "CREATE TABLE recipelist (recipe_ID integer primary key not null autoincrement, " + "menu_ID varchar null default, " + "stock_ID varchar null default, " + "recipe_quantity double null defualt " + ");" ; private final Context context; private static DatabaseHelper DBHelper; private static SQLiteDatabase db; public DBConnect(Context ctx) { this.context = ctx; DBHelper = new DatabaseHelper(context); } public static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } #Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE_TABLE_1); db.execSQL(DATABASE_CREATE_TABLE_2); db.execSQL(DATABASE_CREATE_TABLE_3); } #Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS ipaddress"); db.execSQL("DROP TABLE IF EXISTS menudb"); db.execSQL("DROP TABLE IF EXISTS recipelist"); onCreate(db); } } //---opens the database--- public DBConnect open() throws SQLException { db = DBHelper.getWritableDatabase(); return this; } //---closes the database--- public void close() { DBHelper.close(); } //---insert a title into the database--- public long insertIPAddress(String ipaddress) { ContentValues initialValues = new ContentValues(); initialValues.put(KEY_IP, ipaddress); return db.insert(DATABASE_TABLE_1, null, initialValues); } public String getIP() { String retrievedIP; String query = "SELECT saved_ip_address FROM ipaddress WHERE _id = (SELECT MAX(_id) FROM ipaddress)"; Cursor cursor = db.rawQuery(query, null); retrievedIP= cursor.getString(cursor.getColumnIndex("saved_ip_address")); cursor.close(); return retrievedIP; } public List<ColumnValue[]> select(final String query) { List<ColumnValue[]> result = null; Cursor cursor = db.rawQuery(query, null); if (cursor.moveToFirst()) { result = new ArrayList<ColumnValue[]>(); do { int columns = cursor.getColumnCount(); ColumnValue[] cvarray = new ColumnValue[columns]; for (int i=0; i<columns; i++) { String key = cursor.getColumnName(i); String value = cursor.getString(i); ColumnValue cv = new ColumnValue(key, value); cvarray[i] = cv; } result.add(cvarray); } while (cursor.moveToNext()); } cursor.close(); return result; } public class ColumnValue { public String column, value; public ColumnValue(String c, String v) { column = c; value = v; } } } I think it is on the getID() clause but I can't see anything wrong with it nor my SELECT statetment. What I am trying to do here is to get the value of the saved_ip_address which is at the very bottom of the ipaddress table. Here is my LogCat where the start of error is bolded out. Thank You 01-25 23:51:14.507: WARN/System.err(616): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2 01-25 23:51:14.568: WARN/System.err(616): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:421) 01-25 23:51:14.568: WARN/System.err(616): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:117) 01-25 23:51:14.578: WARN/System.err(616): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:31) 01-25 23:51:14.590: WARN/System.err(616): at com.thesis.menubook.DBConnect.getIP(DBConnect.java:113) 01-25 23:51:14.590: WARN/System.err(616): at com.thesis.menubook.ChooseTable$GetTableDetails$1.run(ChooseTable.java:103) 01-25 23:51:14.622: WARN/System.err(616): at android.os.Handler.handleCallback(Handler.java:587) 01-25 23:51:14.622: WARN/System.err(616): at android.os.Handler.dispatchMessage(Handler.java:92) 01-25 23:51:14.622: WARN/System.err(616): at android.os.Looper.loop(Looper.java:132) 01-25 23:51:14.648: WARN/System.err(616): at android.app.ActivityThread.main(ActivityThread.java:4025) 01-25 23:51:14.688: WARN/System.err(616): at java.lang.reflect.Method.invokeNative(Native Method) 01-25 23:51:14.688: WARN/System.err(616): at java.lang.reflect.Method.invoke(Method.java:491) 01-25 23:51:14.688: WARN/System.err(616): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 01-25 23:51:14.688: WARN/System.err(616): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 01-25 23:51:14.688: WARN/System.err(616): at dalvik.system.NativeStart.main(Native Method) 01-25 23:51:14.998: DEBUG/AndroidRuntime(616): Shutting down VM 01-25 23:51:15.008: WARN/dalvikvm(616): threadid=1: thread exiting with uncaught exception (group=0x40014760) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): FATAL EXCEPTION: main 01-25 23:51:15.138: ERROR/AndroidRuntime(616): java.lang.IllegalArgumentException: Host name may not be null 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at org.apache.http.HttpHost.<init>(HttpHost.java:83) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at org.apache.http.impl.client.AbstractHttpClient.determineTarget(AbstractHttpClient.java:497) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at com.thesis.menubook.JSONParser.makeHttpRequest(JSONParser.java:62) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at com.thesis.menubook.ChooseTable$GetTableDetails$1.run(ChooseTable.java:119) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at android.os.Handler.handleCallback(Handler.java:587) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at android.os.Handler.dispatchMessage(Handler.java:92) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at android.os.Looper.loop(Looper.java:132) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at android.app.ActivityThread.main(ActivityThread.java:4025) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at java.lang.reflect.Method.invokeNative(Native Method) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at java.lang.reflect.Method.invoke(Method.java:491) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 01-25 23:51:15.138: ERROR/AndroidRuntime(616): at dalvik.system.NativeStart.main(Native Method) 01-25 23:51:15.328: WARN/ActivityManager(83): Force finishing activity com.thesis.menubook/.ChooseTable 01-25 23:51:15.958: WARN/ActivityManager(83): Activity pause timeout for ActivityRecord{408b4228 com.thesis.menubook/.ChooseTable} 01-25 23:51:20.048: INFO/Process(616): Sending signal. PID: 616 SIG: 9 01-25 23:51:21.068: INFO/ActivityManager(83): Process com.thesis.menubook (pid 616) has died. 01-25 23:51:21.089: ERROR/InputDispatcher(83): channel '408408d0 com.thesis.menubook/com.thesis.menubook.IPAddress (server)' ~ Consumer closed input channel or an error occurred. events=0x8 01-25 23:51:21.098: ERROR/InputDispatcher(83): channel '408408d0 com.thesis.menubook/com.thesis.menubook.IPAddress (server)' ~ Channel is unrecoverably broken and will be disposed! 01-25 23:51:21.768: INFO/WindowManager(83): WIN DEATH: Window{408408d0 com.thesis.menubook/com.thesis.menubook.IPAddress paused=false} 01-25 23:51:22.108: INFO/WindowManager(83): WIN DEATH: Window{407b66d8 com.thesis.menubook/com.thesis.menubook.ChooseTable paused=false} 01-25 23:51:22.246: INFO/WindowManager(83): WIN DEATH: Window{4097d668 com.thesis.menubook/com.thesis.menubook.ChooseTable paused=false} 01-25 23:51:22.358: INFO/WindowManager(83): WINDOW DIED Window{408408d0 com.thesis.menubook/com.thesis.menubook.IPAddress paused=false} 01-25 23:51:22.449: ERROR/InputDispatcher(83): Received spurious receive callback for unknown input channel. fd=188, events=0x8 01-25 23:51:22.449: ERROR/InputDispatcher(83): Received spurious receive callback for unknown input channel. fd=190, events=0x8 01-25 23:51:23.468: DEBUG/dalvikvm(147): GC_EXPLICIT freed <1K, 4% free 12942K/13383K, paused 285ms+19ms 01-25 23:51:23.858: WARN/InputManagerService(83): Got RemoteException sending setActive(false) notification to pid 616 uid 10004 01-25 23:52:15.278: DEBUG/SntpClient(83): request time failed: java.net.SocketException: Address family not supported by protocol 01-25 23:57:15.589: DEBUG/SntpClient(83): request time failed: java.net.SocketException: Address family not supported by protocol
after getting a Cursor object you need to advance to the first row... cursor.moveToFirst(); prior to fetching from the cursor. also you'll need to check if indeed there are any rows present in the cursor.