Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > method always visible by other class

Reply
Thread Tools

method always visible by other class

 
 
Mariano
Guest
Posts: n/a
 
      03-18-2007
Then I have a class called MyDBConn.java, inside this class there's a
method called GetResultFromPazienti():

MyDBConn.java:
==================================

package cc;

import java.sql.*;

public class MyDBConn {
private Connection myConnection;
private java.sql.Statement stmt;

// ...

public ResultSet getResultFromPazienti2(String query) {
ResultSet rs=null;
try{
rs=stmt.executeQuery(query);
}
catch(Exception e){
alerts.showErr(e.getMessage());
}
return rs;
}

// ...

==================================

After this, I have a class called Paziente.java, from this class I
would call method: getResultFromPazienti2(), class is something like
this:

File: Paziente.java
==================================
package cc;
import java.sql.*;

public class Paziente extends javax.swing.JFrame {
private MyDBConn mdbc;
private java.sql.Statement stmt;

// ...
// ...

private void formWindowOpened(java.awt.event.WindowEvent evt)
{
ResultSet rs=mdbc.getResultFromPazienti2("select ... from ...
where ...");

try {
rs.next();
// ...
txtNome.setText(rs.getString("NOME"));
// ...
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}


==================================

At first moment seem that are not problems, infact there's no problem
in compile time, but when I execute project and method
formWindowOpened() is started an "Exception in thread "AWT-
EventQueue-0" java.lang.NullPointerException", where are the
problems???
Thank you to all....

 
Reply With Quote
 
 
 
 
Brandon McCombs
Guest
Posts: n/a
 
      03-19-2007
Mariano wrote:
> Then I have a class called MyDBConn.java, inside this class there's a
> method called GetResultFromPazienti():


The method below is called GetResultFromPazienti2().

>
> MyDBConn.java:
> ==================================
>
> package cc;
>
> import java.sql.*;
>
> public class MyDBConn {
> private Connection myConnection;
> private java.sql.Statement stmt;
>
> // ...
>


the method below is not the same as you specify above.
You never instantiate stmt so maybe that is what is producing the null
pointer.

> public ResultSet getResultFromPazienti2(String query) {
> ResultSet rs=null;
> try{
> rs=stmt.executeQuery(query);
> }
> catch(Exception e){
> alerts.showErr(e.getMessage());
> }
> return rs;
> }
>
> // ...
>
> ==================================
>
> After this, I have a class called Paziente.java, from this class I
> would call method: getResultFromPazienti2(), class is something like
> this:
>
> File: Paziente.java
> ==================================
> package cc;
> import java.sql.*;
>
> public class Paziente extends javax.swing.JFrame {
> private MyDBConn mdbc;
> private java.sql.Statement stmt;


Is stmt ever used and initialized?
Is mdbc ever initialized? You leave out code that prevents full analysis
so we can't help you.

>
> // ...
> // ...
>
> private void formWindowOpened(java.awt.event.WindowEvent evt)
> {
> ResultSet rs=mdbc.getResultFromPazienti2("select ... from ...
> where ...");
>
> try {
> rs.next();
> // ...
> txtNome.setText(rs.getString("NOME"));
> // ...
> } catch (SQLException ex) {
> ex.printStackTrace();
> }
> }
> }
>
>
> ==================================
>
> At first moment seem that are not problems, infact there's no problem
> in compile time, but when I execute project and method
> formWindowOpened() is started an "Exception in thread "AWT-
> EventQueue-0" java.lang.NullPointerException", where are the
> problems???
> Thank you to all....
>


The exception should tell you what line the null pointer is on. Does it?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why a class can't access protected method from another class in thesame package,the method is interited from the ohtner class from differntpackage? junzhang1983@gmail.com Java 3 01-28-2008 02:09 AM
how to call method of the class which contains a pointer to other class method? Pawel_Iks C++ 3 07-31-2007 06:30 AM
Sections visible and not visible tshad ASP .Net 4 01-31-2005 09:30 PM
button visible/not visible tshad ASP .Net 6 10-28-2004 10:02 PM
Panel.Visible = True also make child controls visible. spamfurnace ASP .Net 1 05-24-2004 03:07 AM



Advertisments