When you declare an object in java the default value it gets is null.
So you declared a class variable driver and hence it gets the value null.
Now in the googletitle method you declared another object driver . So this driver becomes local to that method and what ever you will have scope local. The class variable driver will still be empty
And in tear ...
From what I can see in your question, you have very basic knowledge of Java so that I would recommend to start from learning the concepts of the language. In your particular case you're trying to cast some object to By class that has no parent-child relationships with By class. This is why you get class cast exception.
I also assume that you have done that ...
WebDriver driver = new FirefoxDriver();
WebElement dynamicElement = (new WebDriverWait(driver, 10))
This is the format for webdriver wait
In your code you are down casting a webelement to By which is not allowed
If you need to use ...