How to pass String object as an argument?
Whenever I try to pass any String as an argument error msg occur as - ')' expected

Recommended Answers

All 8 Replies

Well, we can't read over your shoulder. Post the code and perhaps someone can tell you what's wrong with it.

/*
 * SearchResult.java
 *
 * Created on September 3, 2008, 7:01 PM
 */

/**
 *
 * @author  MAUNIK
 */
import javax.swing.*;
import java.util.*;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*; 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;

public class SearchResult extends javax.swing.JFrame {
    
        String sr1="";
        String sr2="";
        String sr3="";
        String sr4="";
        String sr5="";
        String sr6="";
        String sr7="";
        String sr8="";
        String sr9="";
        String sr10="";
        String sr11="";
        String sr12="";
        String sr13="";
        String sr14="";
        String sr15="";
        String sr16="";
        String sr17="";
    /** Creates new form SearchResult */
    public SearchResult(String s){
                    
        sr2 = s;
        
 //                 getComponents();
                  initComponents();
    }
    /*
public void getComponents(SearchResult ob){

    sr1 = ob.sr1;
    sr2 = ob.sr2;
    sr3 = ob.sr3;
    sr4 = ob.sr4;
    sr5 = ob.sr5;
    sr6 = ob.sr6;
    sr7 = ob.sr7;
    sr8 = ob.sr8;
    sr9 = ob.sr9;
    sr10 = ob.sr10;
    sr11 = ob.sr11;
    sr12 = ob.sr12;
    sr13 = ob.sr13;
    sr14 = ob.sr14;
    sr15 = ob.sr15;
    sr16 = ob.sr16;
    sr17 = ob.sr17;
    
    
    
}*/
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("jLabel1" + sr1);

        jLabel2.setText("jLabel2" + sr2);

        jLabel3.setText("jLabel3" + sr3);

        jLabel4.setText("jLabel4" + sr4);

        jLabel5.setText("jLabel5" + sr5);

        jLabel6.setText("jLabel6" + sr6);

        jLabel7.setText("jLabel7" + sr7);

        jLabel8.setText("jLabel8" + sr8);

        jLabel9.setText("jLabel9" + sr9);

        jLabel10.setText("jLabel10" + sr10);

        jLabel11.setText("jLabel11" + sr11);

        jLabel12.setText("jLabel12" + sr12);

        jLabel13.setText("jLabel13" + sr13);

        jLabel14.setText("jLabel14" + sr14);

        jLabel15.setText("jLabel15" + sr15);

        jLabel16.setText("jLabel16" + sr16);

        jLabel17.setText("jLabel17" + sr17);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(43, 43, 43)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .add(8, 8, 8)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel12)
                            .add(jLabel11)
                            .add(jLabel13)
                            .add(jLabel14)
                            .add(jLabel15)
                            .add(jLabel16)
                            .add(jLabel17)))
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jLabel9)
                        .add(jLabel10)
                        .add(jLabel8)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel7)
                            .add(jLabel6)
                            .add(jLabel5)
                            .add(jLabel4)
                            .add(jLabel3)
                            .add(jLabel2)
                            .add(jLabel1))))
                .addContainerGap(309, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .add(14, 14, 14)
                .add(jLabel2)
                .add(17, 17, 17)
                .add(jLabel3)
                .add(16, 16, 16)
                .add(jLabel4)
                .add(19, 19, 19)
                .add(jLabel5)
                .add(20, 20, 20)
                .add(jLabel6)
                .add(16, 16, 16)
                .add(jLabel7)
                .add(15, 15, 15)
                .add(jLabel8)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel9)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel10)
                .add(14, 14, 14)
                .add(jLabel11)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel12)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel13)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel14)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel15)
                .add(9, 9, 9)
                .add(jLabel16)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 12, Short.MAX_VALUE)
                .add(jLabel17))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SearchResult(String s).setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    // End of variables declaration//GEN-END:variables
    
}

we're not going to read that garbage.
You will have gotten a line number for the error, that will tell you where to look for your error.
Learn to read and interpret error messages, it's a vital skill.

Yes, perhaps I should have said post the relevant code and use [code]

[/code] tags, if you want anyone to read it.

As the error says you have probably forgot to put somewhere a ")"

And if you can't debug something that simple or you don't know how to pass arguments, what are you doing writing that complex code (for you skills)?

How many programs that are executed from console have you written?
If you have written enough you should be able to fix this or at least understand that a line where the error has happened is required and not the entire code.
If not then you are moving too fast

new SearchResult(String s).setVisible(true);

Read any reference at all on Java and you will see that this is not the correct way to call a method. Method calls do not include the type with the parameter.

This is HelloWorld-level basic language semantics. I would recommend reading a lot of this: http://www.codeguru.com/java/tij/

commented: Great endurance to read through that, for something like this. ;-) +8
new SearchResult(String s).setVisible(true);

Read any reference at all on Java and you will see that this is not the correct way to call a method. Method calls do not include the type with the parameter.

This is HelloWorld-level basic language semantics. I would recommend reading a lot of this: http://www.codeguru.com/java/tij/

So you did, after all, look at the code? Even though you said you wouldn't? ;-)

Just kidding.

I had the feeling it was this sort of mistake from the beginning, but I definately was not[/i] going to read all of that.

Edit: Ah, you didn't say you wouldn't, just hinted at it. ;-)

Guilty as charged...
:icon_wink:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.