title: How to fix "incompatible types: org.apache.beam.sdk.options.ValueProvider<java.lang.String> cannot be converted to java.lang.String"
body: <p>I followed <a href="https://cloud.google.com/dataflow/docs/guides/templates/creating-templates" rel="nofollow noreferrer">this link</a> to create a template which builds a beam pipeline to read from KafkaIO. But I always encountered " incompatible types: org.apache.beam.sdk.options.ValueProvider cannot be converted to java.lang.String". It is line ".withBootstrapServers(options.getKafkaServer())" which caused the error. Beam version is 2.9.0 and here is part of my code.</p>
  
  <pre><code>public interface Options extends PipelineOptions {
      @Description("Kafka server")
      @Required
      ValueProvider&lt;String&gt; getKafkaServer();
  
      void setKafkaServer(ValueProvider&lt;String&gt; value);
  
      @Description("Topic to read from")
      @Required
      ValueProvider&lt;String&gt; getInputTopic();
  
      void setInputTopic(ValueProvider&lt;String&gt; value);
  
      @Description("Topic to write to")
      @Required
      ValueProvider&lt;String&gt; getOutputTopic();
  
      void setOutputTopic(ValueProvider&lt;String&gt; value);
  
      @Description("File path to write to")
      @Required
      ValueProvider&lt;String&gt; getOutput();
  
      void setOutput(ValueProvider&lt;String&gt; value);
  }
  
  public static void main(String[] args) {
      Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
      Pipeline p = Pipeline.create(options);
  
      PCollection&lt;String&gt; processedData = p.apply(KafkaIO.&lt;Long, String&gt;read()
              .withBootstrapServers(options.getKafkaServer())
              .withTopic(options.getInputTopic())
              .withKeyDeserializer(LongDeserializer.class)
              .withValueDeserializer(StringDeserializer.class)
              .withoutMetadata() 
      )
  </code></pre>
  
  <p>And following is how I run the code:</p>
  
  <pre><code>mvn compile exec:java \
  -Dexec.mainClass=${MyClass} \
  -Pdataflow-runner -Dexec.args=" \
  --project=${MyClass} \
  --stagingLocation=gs://${MyBucket}/staging \
  --tempLocation=gs://${MyBucket}/temp \
  --templateLocation=gs://${MyBucket}/templates/${MyClass} \
  --runner=DataflowRunner"
  </code></pre>