i have 2 class for example class a and class b. i need the string store at class a pass and use by class b, here is my code for class a and class b.

class a

public void actionPerformed(ActionEvent arg0) {
                 JFileChooser fileChooser = new JFileChooser();

                 fileChooser.setFileFilter(new FileNameExtensionFilter("Text Files", "txt"));
                 int returnValue = fileChooser.showOpenDialog(null);
                 if (returnValue == JFileChooser.APPROVE_OPTION) {
                     String test;
                      File selectedFile = fileChooser.getSelectedFile();


class b

            a path = new a();

            FileInputStream fis = new FileInputStream(path.test);
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));

           while((line = br.readLine()) != null) 

       catch(IOException e){
           JOptionPane.showMessageDialog(null, "Error");

im check using System.out.print for String value test for both class. in class a, i can get the correct value, but in class b, i only get null.

You declare String test on line 9 of a. When you declare a variable in Java its scope if from the preceeding '{' to the following '}'. In this case that test variable exists just from line 8 to line 13, after which it is discarded. You presumably have another String test declared somewhere else, and that's the one the b uses.

ps If you are no longer waiting for replies to your previous topic, please mark it "solved". Thank you.

ok, i got it now so i make some changes. but still i cant get the value from class testgui String test value to class b.

public class testgui {

    private JFrame pu;

    String test;

    public static void main(String [] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    testgui window = new testgui();
                } catch (Exception e) {


     * Create the application.
    public testgui() {


i also had try the getter setter method but it still not working. i still cant get the value.

ok, i find out the solution already.

class a
    static String test="testing";

and you can get the String test value from other class by

class b
    "your class name"."the String name"

for example


then it will show the value inside that String.

Why did you declare the String in class 'a' as static?