• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to initiate MouseEvent object in java

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to pass the object of MouseEvent into "Clicked" function


I know I should begin with..

But when it comes to "control.getparent();" by passing the above MouseEvent met
control become null (there is error about null pointer exception)
Is there anyone can help me to fix it (or how to update the source of MouseEvent)??
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be control , doesn't have any parent... I guess..

May be some controls have, may be some controls haven't any parent.. In this case,
it is better to check whether control.getParent() returns null reference before assigning.
 
Qiang Qiang Xi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ranjith Suranga wrote:May be control , doesn't have any parent... I guess..

May be some controls have, may be some controls haven't any parent.. In this case,
it is better to check whether control.getParent() returns null reference before assigning.



Ya, control.getParent() returns null and I still cannot manage to pass the loop. I think may be the initiated MouseEvent object is not good enough to pass it.
 
Ranji Sura
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I still cannot manage to pass the loop



What do you mean by it... ? are you still getting an exception although checking the reference is null ?
 
Qiang Qiang Xi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


What do you mean by it... ? are you still getting an exception although checking the reference is null ?



Yes,I need to cover the codes but I got a nullpoint expection error as it returns null to control.
It seems that the initiated MouseEvent is not good enough.it's too simple with no sources. I try to look at the api but I cannot ways to add some info into the MouseEvent object.
 
Ranji Sura
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show the output of this code please... ?

 
Qiang Qiang Xi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for output, you mean the error message??
they are :
java.lang.NullPointerException
at Page.onNumberItemClicked(UserPage.java:124)
at PageTest.testOnNumberItemClicked(UserPageTest.java:131)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 
Ranji Sura
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Qiang Qiang Xi wrote:for output, you mean the error message??



No, I mean what is the output if you run below code... ?

 
Qiang Qiang Xi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, I dont really know it , as what I have to do is just pass the object in it and run it successfully.
 
Ranji Sura
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. Try with this..
Does it work for you... ?
 
Qiang Qiang Xi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't work and I am not allowed to change the function for testing only
 
Ranji Sura
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Qiang Qiang Xi wrote:It doesn't work and I am not allowed to change the function for testing only



What do you mean by it doesn't work.. ? Are you still getting same exception ?


Are you sure about this code ? I am not sure with this code.. What is Display ? Shell ?
MouseEvent,from which package you have imported it ? in java.awt.Event there is no such Constructor like MouseEvent(Event event)

So.. If you don't mind check your code again..
If you don't get any solution.., Let's wait and see what other peoples have to say ?
reply
    Bookmark Topic Watch Topic
  • New Topic