Java Selenium – Can not use Webdriver apart from "Static void main", in a different function

I use Selenium via Eclipse using Java. I have several pieces of code that I want to shorten with the help of a function. However, the driver is declared in the static void public directory. When I use the following code outside of this, it says "the driver can not be resolved." How can I fix this?

                public void TypeinField (String xpath, String Value) {
String val = value;
Element WebElement = driver.findElement (By.xpath (xpath));
element.clear ();

for (int i = 0; i <value.length (); i ++) {
char c = val.charAt (i);
String s = new StringBuilder (). Append (c) .toString ();
element.sendKeys (s);