Posts

Showing posts with the label Debugging

Check If Object Exists In JavaScript

Answer : You can safely use the typeof operator on undefined variables. If it has been assigned any value, including null, typeof will return something other than undefined. typeof always returns a string. Therefore if (typeof maybeObject != "undefined") { alert("GOT THERE"); } There are a lot of half-truths here, so I thought I make some things clearer. Actually you can't accurately tell if a variable exists (unless you want to wrap every second line into a try-catch block). The reason is Javascript has this notorious value of undefined which strikingly doesn't mean that the variable is not defined, or that it doesn't exist undefined !== not defined var a; alert(typeof a); // undefined (declared without a value) alert(typeof b); // undefined (not declared) So both a variable that exists and another one that doesn't can report you the undefined type. As for @Kevin's misconception, null == undefined . It is due to type c...

Can't Attach Android Studio's Debugger To Android Process

Answer : So finally I got it working, by: Checking 'Show all processes' checkbox! BUT as you see in the question, checkbox was on at the beginning, so there were multiple issues. To summarize, these are other actions to be done: Kill all adb processes (use ps -x | grep adb and kill -9 [process id] ) adb start-server in terminal Reconnect device adb devices (to make sure device is connected successfully) Make sure Android DDMS Devices | logcat shows your app and only one device is listed. Check Show all processes checkbox. See screenshot I solved this way a. Closed Android Studio b. Did adb kill-server from a terminal. Also check the adb process in also killed from the Running processes window in PC c. Started Android Studio d. Android Studio tried to initialize adb again and back to work. It could be because the release build variant (which you can set in the Build-Variants section) has been chosen mistakenly, only debug-variant is debuggabl...