Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6148751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:20:03+00:00 2026-05-23T19:20:03+00:00

I tried hello world example from here and I can’t see any output in

  • 0

I tried hello world example from here and I can’t see any output in my program (in console when using “java” command). Is it something wrong I do? The code of marshal function looks like this:

public void marshal() {
    try {
        JAXBElement<GreetingListType> gl =
            of.createGreetings( grList );
        JAXBContext jc = JAXBContext.newInstance( "hello" );
        Marshaller m = jc.createMarshaller();
        m.marshal( gl, System.out );
    } catch( JAXBException jbe ){
        // ...
    }
}

I tried also tried to put output into a file like this:

public void marshal() {
    try {
        JAXBElement<GreetingListType> gl =
            of.createGreetings( grList );
        JAXBContext jc = JAXBContext.newInstance( "hello" );
        FileOutputStream fos = new FileOutputStream("plik.xml");
        Marshaller m = jc.createMarshaller();
        //m.marshal( gl, System.out );
        m.marshal(gl, fos);
        fos.close();
    } catch( JAXBException jbe ){
        // ...
    }
  catch( IOException ioe ){
    // ...
}
}

but it didn’t work out. Have you got any solutions?

EDIT: After printing Stack Trace it gave me this, looks promising:

javax.xml.bind.JAXBException: "hello" doesnt contain ObjectFactory.class or jaxb.index
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:186)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:148)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:310)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:392)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:357)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:264)
    at Hello.marshal(Hello.java:28)
    at Hello.main(Hello.java:43)

I do have ObjectFactory but don’t know anything about jaxb.index. Is it necessary? How it should look like?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:20:05+00:00Added an answer on May 23, 2026 at 7:20 pm

    The demo appears to be incomplete (missing main method):

    public static void main(String[] args) {
        Hello hello = new Hello();
        hello.make("FOO", "BAR");
        hello.marshal();
    }
    

    Below is the corrected version:

    package hello;
    
    import javax.xml.bind.*;
    
    public class Hello {
    
        private ObjectFactory of;
        private GreetingListType grList;
    
        public Hello(){
            of = new ObjectFactory();
            grList = of.createGreetingListType();
        }
    
        public static void main(String[] args) {
            Hello h = new Hello();
            h.make( "Bonjour, madame", "fr" ); 
            h.make( "Hey, you", "en" ); 
            h.marshal();    }
    
        public void make( String t, String l ){
            GreetingType g = of.createGreetingType();
            g.setText( t );
            g.setLanguage( l );
            grList.getGreeting().add( g );
        }
    
        public void marshal() {
            try {
                JAXBElement<GreetingListType> gl =
                    of.createGreetings( grList );
                JAXBContext jc = JAXBContext.newInstance( "hello" );
                Marshaller m = jc.createMarshaller();
                m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
                m.marshal( gl, System.out );
            } catch( JAXBException jbe ){
                // ...
            }
        }
    
    }
    

    Output

    <?xml version="1.0" encoding="UTF-8"?>
    <Greetings>
       <Greeting language="fr">
          <Text>Bonjour, madame</Text>
       </Greeting>
       <Greeting language="en">
          <Text>Hey, you</Text>
       </Greeting>
    </Greetings>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Hello world applet,taken from book example. HelloWorldApplet.java import java.awt.*; import javax.swing.*;
I want to rewrite an url from example.php?id=123 to example-123-hello-world (where hello-world is some
I have tried to generate Hello World with openxml sdk. To my surprise when
I tried with no success: webBrowser1.Document.ExecCommand(alert('Hello World!'), true, null); also tried: private void webBrowser1_DocumentCompleted(object
I tried running a python script: print Hello, World! And I get this error:
When I tried to do a simple modification of the hello android program that
When I started learning Java I too started with the ubiqutous Hello world app.
Ok lets say I have a URL example.com/hello/world/20111020 (with or without the trailing slash).
hello i am having same issue, i tried your solution but it didnt help
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.