Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Java and Flickr - Help with Inheritance between Main Class and sub-class

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Java and Flickr - Help with Inheritance between Main Class and sub-class

    Dear all,

    I have been doing a small program which can help user search general photos by keywords and can retrieve most recent general uploads from Flickr.

    I created 4 classes:

    testUserInterface => to build all components for interface.


    testSearch => inherits interface from testUserInterface and build event action when user clicks on button start and button exit.


    PhotoFinder => get connection to Flickr.

    Link to view my code of PhotoFinder


    PhotoPanel => displays photos on this panel.

    Link to view my code of PhotoPanel


    When I select sub-menu "Search Photos" from class testUserInterface, a search panel is displayed with textfield and 2 buttons, start and exit.


    However, a problem occurs when I clicks start button (after entering a specific keyword).
    all photos which relates to the keyword is not shown.
    and I got problem with sub-menu instead.



    Please help me out with the problem, it drives me crazy (TT)


  2. #2
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Java and Flickr - Help with Inheritance between Main Class and sub-class

    This section is duplicated, please can admin delete this section for me please.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Java and Flickr - Help with Inheritance between Main Class and sub-class

    The two threads have been merged.

    I got problem with sub-menu instead in line 180.
    Please copy the full text of the error message and paste it here.
    Not images, the lines of text.
    Also post the code where the error happens.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java and Flickr - Help with Inheritance between Main Class and sub-class

    The errors are shown below:

    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JButton cannot be cast to javax.swing.JMenuItem
    at testUserInterface.actionPerformed(testUserInterfac e.java:180)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.jav a:6505)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3321)
    at java.awt.Component.processEvent(Component.java:627 0)
    at java.awt.Container.processEvent(Container.java:222 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4861)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719 )
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:723)
    at java.awt.EventQueue.access$200(EventQueue.java:103 )
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:696)
    at java.awt.EventQueue$4.run(EventQueue.java:694)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 693)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:97)

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Java and Flickr - Help with Inheritance between Main Class and sub-class

    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JButton cannot be cast to javax.swing.JMenuItem
    at testUserInterface.actionPerformed(testUserInterfac e.java:180)
    At line 180 the code is trying to cast a JButton object to a JMenuItem.
    Check the logic at that line to see why it is doing this invalid cast.

    Is the same listener code used by more than one component?

    Without seeing the code it is hard to recommend a fix.

    --- Update ---

    Also posted at Java and Flickr - Help with Inheritance between Main Class and sub-class - Dev Shed
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java and Flickr - Help with Inheritance between Main Class and sub-class

    I found a way to solve the problem with instanceof

    searchk.jpg

    then the error will never be blown up again (^^)

    searchnm.jpg

    However, I face with another problem is, after entering a keyword then click "start" button, no photos are shown up.

    I think I got a problem with panel in testSearch.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Java and Flickr - Help with Inheritance between Main Class and sub-class

    Sorry, I can not see the code from here and have no idea what the problem is.

    If you want help you'll have to post code that will compile, execute and show the problem.

    BTW Posting images of code is a waste of time.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java and Flickr - Help with Inheritance between Main Class and sub-class


  9. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java and Flickr - Help with Inheritance between Main Class and sub-class

    Thanks to copeg, I also got notices from other Moderators in different java 4rums when I return today.
    I only want to archive the answer for my problem much faster but Cross Posting rules let me know more what I can do.

    thanks to Norm, a new error that I get now is java.lang.StackOverflowError

    my aim is to pass txtSearch as an JTextField object from testUserInterface to testSearch.
    However, I got an error saying

    PHP Code:
    java.lang.StackOverflowError
            at java
    .awt.Insets.<init>(Insets.java:103)
            
    at sun.awt.windows.WToolkit.getScreenInsets(Native Method)
            
    at sun.awt.windows.WToolkit.getScreenInsets(WToolkit.java:567)
            
    at java.awt.Window.init(Window.java:498)
            
    at java.awt.Window.<init>(Window.java:536)
            
    at java.awt.Frame.<init>(Frame.java:420)
            
    at java.awt.Frame.<init>(Frame.java:385)
            
    at javax.swing.JFrame.<init>(JFrame.java:180)
            
    at testUserInterface.<init>(testUserInterface.java:65)
            
    at testSearch.<init>(testSearch.java:29)
            
    at testUserInterface.<init>(testUserInterface.java:168


    I posted a question in java-forums.org and waiting for helps.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Java and Flickr - Help with Inheritance between Main Class and sub-class

    at testUserInterface.<init>(testUserInterface.java:65 )
    Is there a recursive call starting at line 65?

    Can you post the code that gets the error?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Java and Flickr - Help with Inheritance between Main Class and sub-class

    Thanks to Norm, I got advise from Fubarable in Java Programming Forum - The Front Page

    I re-build my classes again.

    thanks a lot for your help.

Similar Threads

  1. Java, calling another public class from within the main class giving problems.
    By RandomGaisha in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 26th, 2012, 02:30 PM
  2. Replies: 2
    Last Post: November 18th, 2012, 02:09 PM
  3. need to make basic class and implementation class (base class without void main)
    By javanewbie101 in forum Object Oriented Programming
    Replies: 1
    Last Post: September 19th, 2012, 08:03 PM
  4. create a test class (main method) to start(run) the class in Java
    By curious725 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 1st, 2012, 03:21 AM
  5. Replies: 7
    Last Post: July 21st, 2011, 02:29 PM