Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4343300

Drag and Drop generates EXCEPTION_ACCESS_VIOLATION

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.3.1
    • 1.3.0
    • client-libs
    • ladybird
    • x86
    • windows_nt



        Name: rlT66838 Date: 06/05/2000


        java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
        Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

        jre 1.3 produces the following error

        #
        # An EXCEPTION_ACCESS_VIOLATION exception has been detected in native code
        outside the VM.
        # Program counter=0x5006cecd
        #

        and jre1.3.0rc1 (distributed with Netscape 6 PR1) produces this error

        #
        # HotSpot Virtual Machine Error, EXCEPTION_ACCESS_VIOLATION
        #
        # Error ID: 4F533F57494E13120E43505002BE
        #

        abnormal program termination

        It is generated by this line:
        e.startDrag(new Cursor(Cursor.HAND_CURSOR), transferable, sourceHandler);

        near the end of this Java program, the DragNDrop application in chapter 16 of
        Sams Java 2 Platform Unleashed (a fairly popular book):

        import java.awt.*;
        import java.awt.event.*;
        import java.awt.dnd.*;
        import java.awt.datatransfer.*;
        import java.io.*;

        public class DragNDrop extends Frame {
        int screenWidth = 400;
        int screenHeight = 400;
        Panel panel = new Panel();
        Label topLabel = new Label("Enter text in this text area:");
        Label bottomLabel = new Label("And then drag it to this text area:");
        TextArea textArea1 = new TextArea();
        TextArea textArea2 = new TextArea();

        // Drag and drop variables
        DragSource source = new DragSource();
        DropTarget target = new DropTarget(textArea2, DnDConstants.ACTION_COPY, new DropTargetHandler(), true);
        TextTransfer transferable = new TextTransfer();
        DragSourceHandler sourceHandler = new DragSourceHandler();

        public static void main(String args[]) {
        DragNDrop app = new DragNDrop();
        }

        public DragNDrop() {
        super("DragNDrop");
        setup();
        setSize(screenWidth, screenHeight);
        addWindowListener(new WindowEventHandler());
        show();
        }

        void setup() {
        target.setActive(true);
        panel.setLayout(new GridLayout(4, 1));
        panel.add(topLabel);
        panel.add(textArea1);
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        try {
        toolkit.createDragGestureRecognizer(Class.forName("java.awt.dnd.MouseDragGesture Recognizer"),
        source, textArea1, DnDConstants.ACTION_COPY, new DragHandler());
        }
        catch (ClassNotFoundException ex) {
        System.out.println("Recognizer class not found.");
        System.exit(0);
        }
        panel.add(bottomLabel);
        panel.add(textArea2);
        add("Center", panel);
        }

        class DragSourceHandler implements DragSourceListener {
        public void dropActionChanged(DragSourceDragEvent ev) {
        System.out.println("Source: Drop action changed");
        }

        public void dragEnter(DragSourceDragEvent ev) {
        System.out.println("Source: Drag enter");
        }

        public void dragOver(DragSourceDragEvent ev) {
        }

        public void dragExit(DragSourceEvent ev) {
        System.out.println("Source: Drag exit");
        }

        public void dragDropEnd(DragSourceDropEvent ev) {
        System.out.println("Source: Drag drop end");
        }
        }

        class DropTargetHandler implements DropTargetListener {
        public void dragEnter(DropTargetDragEvent ev) {
        System.out.println("Target: Drag enter");
        DataFlavor df[] = ev.getCurrentDataFlavors();
        for (int i = 0; i < df.length; i++) {
        if (df[i].equals(DataFlavor.plainTextFlavor) ||
        df[i].equals(DataFlavor.stringFlavor)) {
        ev.acceptDrag(DnDConstants.ACTION_COPY);
        return;
        }
        }
        ev.rejectDrag();
        }

        public void dragOver(DropTargetDragEvent ev) {
        }

        public void dragExit(DropTargetEvent ev) {
        System.out.println("Target: Drag exit");
        }

        public void dropActionChanged(DropTargetDragEvent ev) {
        System.out.println("Target: Drop action changed");
        }

        public void drop(DropTargetDropEvent ev) {
        System.out.println("Target: Dropped");
        ev.acceptDrop(DnDConstants.ACTION_COPY);
        Transferable transfer = ev.getTransferable();
        DataFlavor df[] = ev.getCurrentDataFlavors();
        String input = "";
        try {
        for (int i = 0; i < df.length; i++) {
        if (df[i].equals(DataFlavor.stringFlavor) ||
        df[i].equals(DataFlavor.plainTextFlavor)) {
        input = (String) transfer.getTransferData(df[i]);
        }
        }
        textArea2.setText(input);
        }
        catch (Exception e) {
        System.out.println(e.toString());
        }
        try {
        target.getDropTargetContext().dropComplete(true);
        }
        catch (Exception e) {
        }
        }
        }

        class TextTransfer implements Transferable {
        public DataFlavor[] getTransferDataFlavors() {
        DataFlavor flavors[] = new DataFlavor[1];
        flavors[0] = DataFlavor.plainTextFlavor;
        return flavors;
        }

        public boolean isDataFlavorSupported(DataFlavor flavor) {
        return (flavor.equals(DataFlavor.plainTextFlavor));
        }

        public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
        return textArea1.getText();
        }
        }

        class DragHandler implements DragGestureListener {
        public void dragGestureRecognized(DragGestureEvent e) {
        e.startDrag(new Cursor(Cursor.HAND_CURSOR), transferable, sourceHandler);
        }
        }

        class WindowEventHandler extends WindowAdapter {
        public void windowClosing(WindowEvent e) {
        System.exit(0);
        }
        }
        }


        (Review ID: 105662)
        ======================================================================

              dassunw Das Das (Inactive)
              rlewis Roger Lewis (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: