Many a times the problem is that the web elements are not loaded when you execute the code. The best practice is to wait till you find the element and then you try doing operations on the web-element. Here is an example of how to do that:-
try using explicit wait :
WebDriverWait wait = new WebDriverWait(webDriver,60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("q")));
This way selenium will wait till your searchbox will appear in the website.
Hope this helps.