I have this code i java
I have class
class Author
{
String name,surname;
public Author(String name,String surname)
{
this.name=name;
this.surname=surname;
}
public String getAName()
{
return name;
}
public String getASurname()
{
return surname;
}
}
And This code is OK;
I have a button in jFrame class wich adds authors in array
static int nrAuthors=0;
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
Author[] au=new new Author[30];
String name=jTextField22.getText();
String surname=jTextField25.getText();
au[nrAuthors]=new Author(name,surname);
nrAuthors++;
// TODO add your handling code here:
}
And this is OK it means can compile and work properly
but in the other button
I can not have access to the au objects; created objects
private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
au[i].getAName();
}
au.getAName();
does not work.
can somebody show me any idea pls.
I'm working in a web application aspx and C#. I have two procedures in code behind.
protected void Button1_Click(object sender, EventArgs e)
{
...
int totalCost=1000;
Label7.Text = totalCost.ToString();
}
i have this code behind in in button2
protected void Button2_Click(object sender, EventArgs e)
{
...
int bCost=Convert.ToInt32(Label7.Text);
}
I first click button 1 and all is OK when I click button 2 the exeption is thrown at
int bCost=Convert.ToInt32(Label7.Text);
is
Input string was not in a correct format.
Why I can't use the Label7 value from second procedure.
I have created Table in SQL server with visual studio 2005 Table name Student
and table data ID,name, surname, indeks, years,
I have this code in C#
protected void Button1_Click(object sender, EventArgs e)
{
// try
//{
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=\"|DataDirectory|\\db_lab8.mdf\";Integrated Security=True;Connect Timeout=30;User Instance=True");
// ("Data Source=.\\SQLEXPRESS;AttachDbFilename=\"|DataDirectory|\\db_lab8.mdf\";Integrated Security=True;Connect Timeout=30;User Instance=True");
conn.Open();
//
SqlCommand a = new SqlCommand("INSERT INTO Student(ID,name, surname, indeks, years) VALUES ('" + TextBox5.Text + "','" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')", conn);
a.Connection.Open();
a.ExecuteNonQuery();
a.Dispose();
a.Connection.Close();
conn.Close();
Response.Redirect("Default.aspx");
// }
//catch (Exception eee)
//{
// Console.WriteLine("Generic Exception Handler: {0}", eee.ToString());
//}
}
I have tried with try and catch but it doesn't works OK
it just shows the browser and it executes the catch block
without try and catch it shows bug at the line: conn.Open();
and it says
A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
i do not know why I can not attache fie. the process fail
i am doing a project with visual c++ .In my project I have 2 forms . I want to do some calculation of some data of the form Form1, and i want the result of this calculation to write to a label of Form2.
How to do this?
stepen=pow(2,bBita-1-i); in this function the compiler announces error
'pow':ambiguous call to overloaded function
Hi I'm new at this I have created a database Person with (ID,Name,address) in MS SQL
an d I have the following code
protected void Button1_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlConnection conn =new System.Data.SqlClient.SqlConnection();
conn.ConnectionString ="integrated security=SSPI;data source=SQL Server Name;" +"persist security info=False;initial catalog=northwind";
try
{
conn.Open();
string sql = "DELETE FROM Person WHERE ID = 4"; //just as an example is number 4 taken
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
cmd.ExecuteScalar();
// Insert code to process data.
}
catch (Exception ex)
{
}
finally
{
conn.Close();
}
}
I work with Visual Studio 2005. it runs OK no error message but it does not deletes th Person with ID 4 .
You can try like this
Buffered reader tast=new BufferedReader( new InputStreamreader(System.in));
String age="";
age=tast.readLine();
intage=Integer.parseInt(age);
I think that this if kph means speed than distance/kph means time in hours you don't need variable hours. you can simlply write
System.out.println("Time in Hours: "+subtot);
thnx a lot Destin this Was my problem
But it's there implicitly. It works because that superclass has a constructor that takes no arguments.
in th first example means
lass CounterDemo extends Counte
this works OK
class Base
{
int i;
public Base(int i)
{
this.i=i;
}
public void print()
{
System.out.println("Value of i "+i);
}
}
public class MainClass extends Base
{
int i,k;
public MainClass()
{
super(0);
i=0;
}
public static void main(String[] args)
{
MainClass m=new MainClass();
m.print();
}
}
but this not
class Base
{
int i;
public Base(int i)
{
this.i=i;
}
public void print()
{
System.out.println("Value of i "+i);
}
}
public class MainClass extends Base
{
int i,k;
public MainClass()
{
// super(0);
i=0;
}
public static void main(String[] args)
{
MainClass m=new MainClass();
m.print();
}
}
and the meaning of this is that in this case we must call the base constructor with super()
but my question is how in th first class CounterDemo extends Counteexample we do not need super();
I have 2 examples for inheritance in Java The first works but the second not. I wonder why.
Does the extended class must implement constructor with super()
class Counter {
int i = 0;
public Counter()
{
i=1;
}
Counter increment() {
i++;
return this;
}
void print() {
System.out.println("i = " + i);
}
}
public class CounterDemo extends Counter{
public static void main(String[] args) {
Counter x = new Counter();
x.increment().increment().increment().print();
}
}
import java.io.*;
class Base
{
int i;
public Base(int i)
{
this.i=i;
}
public void print()
{
System.out.println("Value of i "+i);
}
}
public class MainClass extends Base
{
int i;
public static void main(String[] args)
{
MainClass m=new MainClass();
}
}
in the second example tells that "Cant find symbol constructor Base()"
Another solution
int Prime(int k)
{
int x;
for(int i=1;i<k;i++)
if(k%i==0) x++;
return x;
}
in main method u have to write
int 9;
if(prime(9)>1)
cout<<"9 is prime ";
else cout<<"not prime";
3 years before I used Borland C++ compiler and their editor to and I didn't have to make new project to compile. I just opened I single Cpp file and click Compile and than Run and everything was OK . I'm interested to, to know how to compile a single .cpp file without making new project in Visual Studio probably it is possible.