How to call methods from One class in Another in TestNG + Eclipse , Please Help Me.

6,770 views
Skip to first unread message

pradeep kattekola

unread,
Apr 21, 2012, 6:55:23 AM4/21/12
to Selenium Users
Dear Team,

As i am trying to call the methods of one class to another as java
code ,

I am getting error as java.lang.NullPointerException.

i have two classes class A and class B.

I want to use the methods of class A in Class B.

can any one please help me out. I searched in google but not able to
find exact solution.

Help me to get out from this issue.


Regards,
Prathip

Senthilkumar P

unread,
Apr 21, 2012, 7:11:59 AM4/21/12
to seleniu...@googlegroups.com
Hi Pradeep,

                   I don't know what happens in u r TestNG code, I hope the below sample code ll help u.

Class A

public class A {

    static void method1()
    {
        System.out.println("Selenium_1");
    }
    static void method2()
    {
        System.out.println("Selenium_1");
    }
   
}


Class B

public class B extends A {

   
    public static void main(String ar[])
    {
        method1();
        method2();
    }
}





--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


pradeep kattekola

unread,
Apr 21, 2012, 7:22:18 AM4/21/12
to Selenium Users
thanks for your reply.. i tried same but

i am getting Null Pointer exception i.e java.lang.NullPointerException

after executing.

Regards

prathip

Senthilkumar P

unread,
Apr 21, 2012, 7:44:52 AM4/21/12
to seleniu...@googlegroups.com
did u execute my sample code??

Class A and B


prathip

Krishnan Mahadevan

unread,
Apr 21, 2012, 8:37:46 AM4/21/12
to seleniu...@googlegroups.com
Without providing the stacttrace and the code that is causing problems merely stating the xception alone is not going to help anyone. 

Please try and provide as much information as possible. 


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

sac

unread,
Apr 23, 2012, 2:28:46 AM4/23/12
to Selenium Users
Try this one ....
*Class A*

public class A {

static void method1()
{
System.out.println("Selenium_1");
}
static void method2()
{
System.out.println("Selenium_1");
}

}

*Class B*
public class B {

public static void main(String ar[])
{
A t= new A();
try{
t.method1();
t.method2();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}


On Apr 21, 3:55 pm, pradeep kattekola <pradeepkattek...@gmail.com>
wrote:

Mark Collin

unread,
Apr 23, 2012, 4:35:08 AM4/23/12
to seleniu...@googlegroups.com
If you don't know how to do this you either need to re-evaluate your choice of language bindings and looks at a programming language you understand, or you need to do some Java training before you jump in to automation with Selenium and Java.

Your question is about a basic a Java question as you can get.

pradeep kattekola

unread,
Apr 26, 2012, 2:05:51 AM4/26/12
to Selenium Users
Dear Team,

Here I am pasting my exact scenerio.


IN eclipse , I created one project i. e myproject

Under myproject i created two classes name class1 and class2 with
default package.

In class1 my code is like this..
------------------------------------------------------------------------------------------
public class class1 extends SeleneseTestCase {
@BeforeClass
public void setUp() throws Exception {
--code--//seleniumRC connection
}

@Test
public void testMethod1() throws Exception {

--code--
}

------------------------------------------------------------------------------------------


In class 2 when i am calling the method of class 1 like below,

public class class 2 extends class1{
class1 c = new class1();
@BeforeClass
public void setUp() throws Exception {
---code---
}

@Test
public void testmethod2() throws Exception {

c.testMethod1(); // I am calling here the methods of class1

}


------------------------------------------------------------------------------------------------


When i am executing TestNG of Class 2 ,

I am getting Nullpointer Exception on c.testMethod1();

java.lang.NullPointerException.

Please any on give the idea how to call methods of different classes
in selenium RC using testNG code.


Regards,
Prathip





Krishnan Mahadevan

unread,
Apr 26, 2012, 2:10:07 AM4/26/12
to seleniu...@googlegroups.com
Pradeep,

This has nothing to do either Selenium Nor TestNG.

This is a straight forward JAVA error. I suggest that you please spend sometime trying to get the basics of Java right, before diving into TestNG or Selenium.

In Inheritance you dont create base class objects within child classes in order to access base class methods, you merely access them as if they were the methods in the child class itself, which is what Inheritance is all about.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Gulshan Saini

unread,
Apr 26, 2012, 3:06:40 AM4/26/12
to seleniu...@googlegroups.com
Post code contained in c.testMethod1(); 

Thanks
Gulshan Saini

pradeep kattekola

unread,
Apr 26, 2012, 3:14:38 AM4/26/12
to Selenium Users
Dear Gulshan ,

I written datadriven code of excel in testMethod1().

thanks krishnan for your clarification..i think i need to learn java
first.
can u have any examples for same.


Regards,
Prathip

Krishnan Mahadevan

unread,
Apr 26, 2012, 3:18:29 AM4/26/12
to seleniu...@googlegroups.com
Pradeep,
There are plenty of online materials that you could google for. Pick a tutorial site that best suites you.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Milena Paz

unread,
Apr 18, 2018, 6:40:42 PM4/18/18
to Selenium Users
Mark Collin, 

Your response is not nice, friendly nor smart. If you don't know how you can help someone, you need to do some guidance training before jumping into a discussion such as this. 

⇜Krishnan Mahadevan⇝

unread,
Apr 18, 2018, 10:17:24 PM4/18/18
to seleniu...@googlegroups.com
Any specific reason for reviving a 6 year old thread?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

bsh...@gmail.com

unread,
Apr 19, 2018, 12:11:07 AM4/19/18
to seleniu...@googlegroups.com
Hello,
I am a newbie too, but I think you should have an obj of class A instantiated in class B, to be able to call methods from A into B. Hope this helps you.



Sent from my iPhone

Milena Paz

unread,
Apr 19, 2018, 9:16:13 AM4/19/18
to seleniu...@googlegroups.com
Maybe because its online forever. Has selenium expired? no, it hasn't. Its still in use. If you don't want your comments to be timeless, don't post online. Else you can create your own site, then stop hosting it after 6 years. 

On Wed, Apr 18, 2018 at 10:16 PM, ⇜Krishnan Mahadevan⇝ <krishnan.ma...@gmail.com> wrote:
Any specific reason for reviving a 6 year old thread?
On Thu, Apr 19, 2018, 04:10 Milena Paz <mpaz....@gmail.com> wrote:
Mark Collin, 

Your response is not nice, friendly nor smart. If you don't know how you can help someone, you need to do some guidance training before jumping into a discussion such as this. 







On Monday, April 23, 2012 at 4:35:08 AM UTC-4, Mark Collin wrote:
If you don't know how to do this you either need to re-evaluate your choice of language bindings and looks at a programming language you understand, or you need to do some Java training before you jump in to automation with Selenium and Java.

Your question is about a basic a Java question as you can get.

On Saturday, 21 April 2012 11:55:23 UTC+1, pradeep kattekola wrote:
Dear Team,

As i am trying to call the methods of one class to another as java
code ,

I am getting error as java.lang.NullPointerException.

i have two classes  class A and class B.

I want to use the methods of class A in Class B.

can any one please help me out. I searched in google but not able to
find exact solution.

Help me to get out from this issue.


Regards,
Prathip

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CANikZLk_3xDCD6EmRJJmRVX-ML3hemwTvRkfTmg6nSCSsaAZ0A%40mail.gmail.com.

⇜Krishnan Mahadevan⇝

unread,
Apr 19, 2018, 9:18:43 AM4/19/18
to Selenium Users
Still trying to understand what is the point that you are trying to drive at ? Please clarify

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Thu, Apr 19, 2018 at 6:45 PM, Milena Paz <mpaz....@gmail.com> wrote:
Maybe because its online forever. Has selenium expired? no, it hasn't. Its still in use. If you don't want your comments to be timeless, don't post online. Else you can create your own site, then stop hosting it after 6 years. 
On Wed, Apr 18, 2018 at 10:16 PM, ⇜Krishnan Mahadevan⇝ <krishnan.mahadevan1978@gmail.com> wrote:
Any specific reason for reviving a 6 year old thread?
On Thu, Apr 19, 2018, 04:10 Milena Paz <mpaz....@gmail.com> wrote:
Mark Collin, 

Your response is not nice, friendly nor smart. If you don't know how you can help someone, you need to do some guidance training before jumping into a discussion such as this. 







On Monday, April 23, 2012 at 4:35:08 AM UTC-4, Mark Collin wrote:
If you don't know how to do this you either need to re-evaluate your choice of language bindings and looks at a programming language you understand, or you need to do some Java training before you jump in to automation with Selenium and Java.

Your question is about a basic a Java question as you can get.

On Saturday, 21 April 2012 11:55:23 UTC+1, pradeep kattekola wrote:
Dear Team,

As i am trying to call the methods of one class to another as java
code ,

I am getting error as java.lang.NullPointerException.

i have two classes  class A and class B.

I want to use the methods of class A in Class B.

can any one please help me out. I searched in google but not able to
find exact solution.

Help me to get out from this issue.


Regards,
Prathip

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

Milena Paz

unread,
Apr 19, 2018, 9:20:36 AM4/19/18
to seleniu...@googlegroups.com
Then keep reading.

On Thu, Apr 19, 2018, 9:18 AM ⇜Krishnan Mahadevan⇝ <krishnan.ma...@gmail.com> wrote:
Still trying to understand what is the point that you are trying to drive at ? Please clarify

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Thu, Apr 19, 2018 at 6:45 PM, Milena Paz <mpaz....@gmail.com> wrote:
Maybe because its online forever. Has selenium expired? no, it hasn't. Its still in use. If you don't want your comments to be timeless, don't post online. Else you can create your own site, then stop hosting it after 6 years. 
On Wed, Apr 18, 2018 at 10:16 PM, ⇜Krishnan Mahadevan⇝ <krishnan.ma...@gmail.com> wrote:
Any specific reason for reviving a 6 year old thread?
On Thu, Apr 19, 2018, 04:10 Milena Paz <mpaz....@gmail.com> wrote:
Mark Collin, 

Your response is not nice, friendly nor smart. If you don't know how you can help someone, you need to do some guidance training before jumping into a discussion such as this. 







On Monday, April 23, 2012 at 4:35:08 AM UTC-4, Mark Collin wrote:
If you don't know how to do this you either need to re-evaluate your choice of language bindings and looks at a programming language you understand, or you need to do some Java training before you jump in to automation with Selenium and Java.

Your question is about a basic a Java question as you can get.

On Saturday, 21 April 2012 11:55:23 UTC+1, pradeep kattekola wrote:
Dear Team,

As i am trying to call the methods of one class to another as java
code ,

I am getting error as java.lang.NullPointerException.

i have two classes  class A and class B.

I want to use the methods of class A in Class B.

can any one please help me out. I searched in google but not able to
find exact solution.

Help me to get out from this issue.


Regards,
Prathip

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
Apr 19, 2018, 9:23:54 AM4/19/18
to Selenium Users
Sure. Please keep posting as well !

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Thu, Apr 19, 2018 at 6:49 PM, Milena Paz <mpaz....@gmail.com> wrote:
Then keep reading.

On Thu, Apr 19, 2018, 9:18 AM ⇜Krishnan Mahadevan⇝ <krishnan.mahadevan1978@gmail.com> wrote:
Still trying to understand what is the point that you are trying to drive at ? Please clarify

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Thu, Apr 19, 2018 at 6:45 PM, Milena Paz <mpaz....@gmail.com> wrote:
Maybe because its online forever. Has selenium expired? no, it hasn't. Its still in use. If you don't want your comments to be timeless, don't post online. Else you can create your own site, then stop hosting it after 6 years. 
On Wed, Apr 18, 2018 at 10:16 PM, ⇜Krishnan Mahadevan⇝ <krishnan.mahadevan1978@gmail.com> wrote:
Any specific reason for reviving a 6 year old thread?
On Thu, Apr 19, 2018, 04:10 Milena Paz <mpaz....@gmail.com> wrote:
Mark Collin, 

Your response is not nice, friendly nor smart. If you don't know how you can help someone, you need to do some guidance training before jumping into a discussion such as this. 







On Monday, April 23, 2012 at 4:35:08 AM UTC-4, Mark Collin wrote:
If you don't know how to do this you either need to re-evaluate your choice of language bindings and looks at a programming language you understand, or you need to do some Java training before you jump in to automation with Selenium and Java.

Your question is about a basic a Java question as you can get.

On Saturday, 21 April 2012 11:55:23 UTC+1, pradeep kattekola wrote:
Dear Team,

As i am trying to call the methods of one class to another as java
code ,

I am getting error as java.lang.NullPointerException.

i have two classes  class A and class B.

I want to use the methods of class A in Class B.

can any one please help me out. I searched in google but not able to
find exact solution.

Help me to get out from this issue.


Regards,
Prathip

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAP94aRNfAz2wxwiegnu-QoahZacPf%2BsYC7xig6hfm9wY4i8htA%40mail.gmail.com.

somasekhar patil

unread,
Apr 19, 2018, 9:28:36 AM4/19/18
to seleniu...@googlegroups.com
thank you


Somasekhar Patil



On Thu, Apr 19, 2018 at 6:45 PM, Milena Paz <mpaz....@gmail.com> wrote:
Maybe because its online forever. Has selenium expired? no, it hasn't. Its still in use. If you don't want your comments to be timeless, don't post online. Else you can create your own site, then stop hosting it after 6 years. 
On Wed, Apr 18, 2018 at 10:16 PM, ⇜Krishnan Mahadevan⇝ <krishnan.mahadevan1978@gmail.com> wrote:
Any specific reason for reviving a 6 year old thread?
On Thu, Apr 19, 2018, 04:10 Milena Paz <mpaz....@gmail.com> wrote:
Mark Collin, 

Your response is not nice, friendly nor smart. If you don't know how you can help someone, you need to do some guidance training before jumping into a discussion such as this. 







On Monday, April 23, 2012 at 4:35:08 AM UTC-4, Mark Collin wrote:
If you don't know how to do this you either need to re-evaluate your choice of language bindings and looks at a programming language you understand, or you need to do some Java training before you jump in to automation with Selenium and Java.

Your question is about a basic a Java question as you can get.

On Saturday, 21 April 2012 11:55:23 UTC+1, pradeep kattekola wrote:
Dear Team,

As i am trying to call the methods of one class to another as java
code ,

I am getting error as java.lang.NullPointerException.

i have two classes  class A and class B.

I want to use the methods of class A in Class B.

can any one please help me out. I searched in google but not able to
find exact solution.

Help me to get out from this issue.


Regards,
Prathip

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages