title: Cannot cast from Graphics to Graphics2D
body: <p>My program code is here:</p>
  
  <pre><code>package Chapter12;
  
  import java.awt.*;
  import javax.swing.*;
  
  public class Pv2 extends JPanel {
  
      public static void main (String []args){
  
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(500,500);
          frame.setVisible(true);
          frame.setContentPane(new Pv2());
  
  
  
  
      }
  
      @Override
      public void paintComponent(Graphics g){
  
          Graphics2D g2 = (Graphics2D) g;
      }
  
  
  
  }
  </code></pre>
  
  <p>Eclipse shows this error when I'm trying to compile the code.</p>
  
  <pre><code>Cannot cast from Graphics to Graphics2D
  </code></pre>
  
  <p>This error occurs on this line :</p>
  
  <pre><code>Graphics2D g2 = (Graphics2D) g;
  </code></pre>
  
  <p>Tried jre 1.6 and jre 1.7 - the same thing. Why the cast isn't allowed? I even tried to download some prepared codes and the error was the same.</p>