All Questions
1,866,707
questions
209
votes
12answers
3.0m views
What is a NullPointerException, and how do I fix it?
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?
What methods/tools can be used to determine the cause so that you stop the exception from causing the program ...
2470
votes
23answers
332k views
How to make a great R reproducible example
When discussing performance with colleagues, teaching, sending a bug report or searching for guidance on mailing lists and here on Stack Overflow, a reproducible example is often asked and always ...
5779
votes
42answers
1.6m views
How do I return the response from an asynchronous call?
I have a function foo which makes an asynchronous request. How can I return the response/result from foo?
I tried returning the value from the callback, as well as assigning the result to a local ...
2773
votes
28answers
1.8m views
How can I prevent SQL injection in PHP?
If user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection, like in the following example:
$unsafe_variable = $_POST['user_input'];
...
1621
votes
36answers
3.0m views
RegEx match open tags except XHTML self-contained tags
I need to match all of these opening tags:
<p>
<a href="foo">
But not these:
<br />
<hr class="foo" />
I came up with this and wanted to make sure I've got it right. I am ...
1874
votes
28answers
1.5m views
What is a NullReferenceException, and how do I fix it?
I have some code and when it executes, it throws a NullReferenceException, saying:
Object reference not set to an instance of an object.
What does this mean, and what can I do to fix this error?
724
votes
23answers
4.0m views
How do I compare strings in Java?
I've been using the == operator in my program to compare all my strings so far.
However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.
Is == bad? When should it ...
1242
votes
28answers
1.8m views
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
I'm running a PHP script and continue to receive errors like:
Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php on line 10
Notice: Undefined index: my_index C:\wamp\www\...
3177
votes
31answers
346k views
Is floating point math broken?
Consider the following code:
0.1 + 0.2 == 0.3 -> false
0.1 + 0.2 -> 0.30000000000000004
Why do these inaccuracies happen?
4238
votes
1answer
2.5m views
The Definitive C++ Book Guide and List
This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year.
Unlike many other programming languages, which are often picked up on the go from ...
2548
votes
12answers
229k views
Why shouldn't I use mysql_* functions in PHP?
What are the technical reasons for why one shouldn't use mysql_* functions? (e.g. mysql_query(), mysql_connect() or mysql_real_escape_string())?
Why should I use something else even if they work on ...
1573
votes
34answers
623k views
What is an undefined reference/unresolved external symbol error and how do I fix it?
What are undefined reference/unresolved external symbol errors? What are common causes and how to fix/prevent them?
Feel free to edit/add your own.
683
votes
18answers
592k views
PHP parse/syntax errors; and how to solve them
Everyone runs into syntax errors. Even experienced programmers make typos. For newcomers, it's just part of the learning process. However, it's often easy to interpret error messages such as:
PHP ...
1677
votes
23answers
896k views
Event binding on dynamically created elements?
I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off.
This happens on page ready ...
2926
votes
44answers
399k views
JavaScript closure inside loops – simple practical example
var funcs = [];
// let's create 3 functions
for (var i = 0; i < 3; i++) {
// and store them in funcs
funcs[i] = function() {
// each should log its value.
console.log("My value: " + i);
...