Cannot Get XML Output In Simple JAXB Example
Jul 7, 2014
[URL] I am unable to get any XML output. I am unable to figure out how to send the contents of System.out to a String that can be printed. I saw an SO post and tried using ByteOutputStreamArray, but that did not work.
XML Schema -
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.0">
<xsd:element name="Greetings" type="GreetingListType" />
<xsd:complexType name="GreetingListType">
<xsd:sequence>
[code]....
View Replies
ADVERTISEMENT
Nov 7, 2014
I am suppose to have a method called save() which should marshall the list of computer parts in the right panel to an XML file. In reverse, another method called load() that should unmarshall the saved XML file back into an object. So basically, the Save event will call save() method and save the list of parts in the right panel to an XML file. The Load event should clear the right panel, and call load() method. When load() is called, it should display the unmarshalled data in the right panel. I got "Exit" to work.
I'm having hard time figuring out the "Load" and "Save" parts though.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PCParts implements ActionListener{
[code]...
View Replies
View Related
Feb 25, 2015
In my app, I'm reading a xml file (with JAXB) but there is times that I have empty segments. I put some examples :
<tuv> <seg>Unknown: the action taken should always be known</seg> </tuv>
Here I read well the tag "seg", I can get all text "Unknown: the action taken should always be known" but if this text is like this:
<tuv> <seg><bpt i="1" x-wb-tag="b1" />Unknown<ept i="1" x-wb-tag="/b1" />: the action taken should always be known</seg> </tuv>
I don't get anything, my variable is empty and I want to get all text "Unknown: the action taken should always be known"
Could I get this text
"<bpt i="1" x-wb-tag="b1" />Unknown<ept i="1" x-wb-tag="/b1" />: the action taken should always be known"
Or only "Unknown: the action taken should always be known" (without tag "ept" and "bpt"? (I want this like a string)
My variable's value is a "string" ....
View Replies
View Related
Mar 10, 2015
I need to transformation the txt files into xml files, but each row txt files don't have same elements, for example the first book is composite one author
<books>
<book>Title</book>
<price>price</price>
<author>Author</author>
</books>
but the second book is composite two author
<books>
<book>Title</book>
<price>price</price>
<author>Author</author>
<author>Author2</author>
</books>
I would have the xml files with the number of authors variables, I can use JAXB for my problem?or not?
View Replies
View Related
Feb 15, 2015
my output fails to display me the 2nd output.Here's my code.
import java.util.Scanner;
public class year
{
public static void main (String [] args)
{
Scanner console = new Scanner (System.in);
System.out.print("Enter the choice of book(A-ABC,D-EFG):");
String x = console.next();
System.out.print("Enter the rate (1-3):");
int y= console.nextInt();
System.out.print("Enter number of kids reading:");
int k = console.nextInt();
[code]....
When I key '0" for kids, it did not appear the second print out. I don't want the first print out to be the output.
View Replies
View Related
Nov 25, 2014
This code models a simple ATM machine that can deposit, withdraw, and show the 10 latest transactions in an array of 10 index values.
My problem is that I can't get the balance right after 10 deposits, the balance only seems to sum the values in my array, not including the transactions made before those ten.
import java.util.Scanner;
public class cashier2 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int amount = 0;
[Code] ....
View Replies
View Related
Mar 11, 2002
I coded up a simple applet and some html with an applet tag and it tested out OK using the applet viewer. But it doesn't do anything (except draw a grey empty box 100x200) when executed from the application server. For the applicaton server test, I put the applet tag in the HTML Body of the JSP page i.e.
<applet code=CatApplet.class height=100 width=200> </applet>
The applet class file is in the same directory as the JSP page. The source for it is:
import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;import java.net.*;
import java.util.Date;public class CatApplet extends JApplet{public void init (){setBackground(Color.green);
resize (250,100);}public void paint (Graphics g){g.drawString ("lets get some cat gui going", 35, 15);}}
Why won't my applet run when the applet tags are in the JSP page?
View Replies
View Related
Feb 4, 2015
I'm just starting to learn Java GUI. I'm trying to make a simple GUI that will update dynamically but having trouble ending the loop correctly.The Currently I've got the GUI updating and stopping, but the Test class method loop does not terminate correctly, it continues to count.
import java.awt.*; // Using AWT container and component classes
import java.awt.event.*; // Using AWT event classes and listener interfaces
import java.util.Timer;
import java.util.TimerTask;
[code]....
View Replies
View Related
Apr 10, 2014
I'm not sure what is wrong with my code:
import java.util.Scanner;
public class Main {
int age = 0;
System.out.println("Enter your age: ");
// Read in values
age = in.nextInt();
}
The in is underlined, telling me "cannot find symbol"
View Replies
View Related
Nov 23, 2014
I'm getting back into the swing of things with Java after using I'm asked to utilize a simple GUI in order to take in the starting data, I cannot seem to get this to work. I'm getting this error Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at Input.buildPanel(Input.java:53)
at Input.<init>(Input.java:27)
at InputDemo.main(InputDemo.java:5)
I've created two classes
import javax.swing.*;
public class Input extends JFrame {
private JPanel panel;
private JLabel messageLabel;
private JLabel messageLabel1;
private JLabel messageLabel2;
private JTextField shiftHrs;
[code]....
View Replies
View Related
Sep 15, 2014
Okay, so I'm looking for a way to synthesize sound, and from what I've found around the interwebs it seems amazingly complex. Is there really not a function like "sound(wavelength, time)"? Alternatively a way to use an integer array to determine the acoutstic pressure at a given time, or some other way to determine the pressure at a given time?
View Replies
View Related
Oct 8, 2014
import javax.swing.JOptionPane;
public class Calculator {
public static void main ( String args[] ) {
double n1 = Double.parseDouble(JOptionPane.showInputDialog(" Enter first number: "));
double n2 = Double.parseDouble(JOptionPane.showInputDialog(" Enter second number: "));
String x = JOptionPane.showInputDialog("Enter operator: ");
double result;
[code].....
Write a program that mimics a calculator. The program will need to accept as input two numeric double values, and accept the operation to be performed as the third input. The operation to be performed will be input in the form of the character representing the java operator for the operation to be performed (i.e + for addition, - for subtraction, * for multiplication, / for division, or % for modulus). Once the program has read these 3 inputs it should output the numbers, the operator, and the result. (For division, if the denominator is zero, the program will output an appropriate message (i.e division by zero is an invalid operation). Please use the JOptionPane class for both accepting the required inputs and for the required output demonstrated below.Some sample output may look as follows:
3 + 4 = 7
13 * 5 = 65
10 / 3 = 3.33333333
Error Messages:
3 errors found:
File: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java [line: 23]
Error: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java:23: 'else' without 'if'
File: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java [line: 31]
Error: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java:31: 'else' without 'if'
File: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java [line: 37]
Error: /Users/gcaruso/Documents/CISS 110/Module 3/Module 4/Calculator.java:37: 'else' without 'if
View Replies
View Related
Dec 14, 2014
I have my program set up I thought correctly. When I click the buttons, nothing is happening.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RobertMaloneChapter18 extends JFrame
{
//set final sizes for window
private static final int WIDTH = 300;
private static final int HEIGHT = 200;
[code]....
View Replies
View Related
Jan 17, 2014
I am currently enrolled in my first Java class. I have taken C# in the past so I've messed with some regular expressions, but I am having trouble finding a good website for Java. Is the syntax the same?I want to create a regular expression to only allow the following characters: c C f F [and any 1-3 digit number].
View Replies
View Related
Jun 28, 2014
I was learning Java and there was this exersize to construct a simple pyramid of prespecified height and width. The program i wrote is turining up with the wrong result.
package asgn2;
import acm.graphics.*;
import acm.program.*;
public class pyramid extends GraphicsProgram {
private static final int BRICK_WIDTH = 30;
private static final int BRICK_HEIGHT = 12;
private static final int BASE_BRICKS =14;
[code]...
View Replies
View Related
Aug 12, 2014
I am new to JSF. I am looking for a sample example to work with JSF using MVC framework. I searched on the net but can not found any simple examples to start with, JSF + MVC.good examples to work with simple examples for JSF + MVC.
View Replies
View Related
Jan 12, 2014
Started java a couple days ago, and now im working on a calculator. But i'm having a problem with else-if statement. I've made a simple version of the problem here so its easier to identify. If i type in 17, it will give me the answer that i want it to. But if i type in 38, nothing happens.
Java Code:
import static java.lang.System.out;
import java.util.Scanner;
public class Firstclass {
public static void main(String[] args) {
Scanner answer = new Scanner(System.in);
out.println("Whats your name?");
if (answer.nextLine().equals("bob")) {
out.println("How old are you?:");
if (answer.nextLine().equals("17")) {
out.println("Nice");
} else if (answer.nextLine().equals("38")) {
out.println("good");
}
}
}
} mh_sh_highlight_all('java');
View Replies
View Related
Sep 1, 2014
i have this source code...
import java.util.Scanner;
//I had to use scanner in this program because I had to create objects that were in the Scanner class, such as in row 16.
* This program confirms a password typed into a *
* console window *
*/
public class Homework1 {
public static void main(String[] args) {
//Needs to add a scanner to the program to continue on
Scanner keyboard = new Scanner(System.in);
[code]....
Now I need to create a second version of this program that uses JOptionPane to get the inputs from the user and show the output!
View Replies
View Related
Apr 9, 2014
This is a simple project that i was using to test my current java knowledge (kinda like revision) and for that i used two classes to make a simple averaging program. i know i0m making it more difficult but like i said i'm testing myself but i come up with an unexpected error. Here's the code:
- 1st Class
import java.util.Scanner;
public class Main {
public static int num;
public static int total = 0;
public static int average;
[Code].....
Now the problem is after inputing the numbers it doesn't give me the average but the value of 0.
View Replies
View Related
Mar 26, 2015
I'm trying to read lines from a textfile and count all the words using String Tokenizer. However I keep getting an error "Unhandled exception type FileNotFoundException" on my IDE(Eclipse) referring to lines 13 and 8. When I let the IDE automatically, and I've even tried typing this manually, insert a try-catch block more errors show up concerning inputFile. When I insert the throws FileNotFoundException for each method it compiles but after running it gives me a FileNotFoundException for textfile.txt. What's even more interesting is that when I copy the .java file out of the IDE project folder, place it in a random empty folder on the Desktop with the textfile.txt, and try running it through command line, it gives a NoSuchElementException: No line found.
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.*;
[Code].....
View Replies
View Related
May 8, 2015
how to structure simple programs (i.e. one-method algorithms for a simple purpose). There are a few different ways that I have been doing it, but I want to be consistent. Should I put both the one-method algorithm (e.g. a factorial function) and the main method that executes the algorithm into the same class and then export it to an executable .jar file for use? Or should I create one class for the algorithm and another for the main method that executes the algorithm? In addition, is there any reason that I should out these classes in a package before I export it?
As another similar question, if I have constructed two distinct classes with two separate purposes, and they are both used in the construction of a single program, then would it be best to just put the main method in a third, separate class or should I put it in one of the two classes?
View Replies
View Related
Nov 1, 2014
I have to write an encryption/decryption program for a sentence entered by the user that uses arrays. Here is my code so far. I'm kind of lost on what to do next in the code.
import java.util.Scanner;
/*Program that encrypts then decrypts a sentence
Encryption
*/
public class Encryption extends java.swing.JFrame{
[code]....
View Replies
View Related
Aug 30, 2014
Use Java to write and run a simple console-window program for checking passwords. The program must satisfy the following requirements:
-When the program runs, it should first print its name, e.g., Password Checker
-The program should next prompt the user to enter a username, e.g.,
Please enter your username:
-The program should next prompt the user to enter a password, e.g., Please enter your password:
- If the user enters a correct password, i.e., one that matches an internal secret password, the program responds. You are approved by access control!, and quits.
-If the user enters an incorrect password, the program responds
Try again:
-If the user enters a correct password matching the secret one, the program responds. You are approved by access control!, and quits.
-If the user enters an incorrect password, the program responds
package class1;
import java.util.Scanner;
public class class1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
[code]....
View Replies
View Related
May 28, 2014
I am new to DreamInCode! I was creating a game using OpenGL (and slick for textures).
Using Vector3f, I make coordinates to where my camera is camera'ing (and rotation).
It was working... until I modified something. I only added shaders. When I took the shaders off I think I might of accidentally deleted something. Nonetheless the code looks perfect to me.
On the method "input()" everything runs. No errors are thrown anywhere. I have syso'd the hell outa my code. It shows no signs of breaks. I can, however, move elements I put into my program. I am 100% sure that no other class is breaking my game (soon to be).
What you should look out for: I am not really sure about the glLoadIdentity()'s and glMatrixMode(). I am, knowing a good part of, thinking it could be gluViewPort....
My problem: Can't move my camera even tho it was working before.
package com.Hydroque.OpenGlTest;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluPerspective;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
[Code] ....
View Replies
View Related
Feb 13, 2015
i want to build a simple x,y grid in eclipse. Where an simple agent can search for a goal and end the episode.
I have java experience but I cant get my head around something simple as this.
I know there will be state, actions and environment and agent class.
But I cannt figure out where to start with this, do i start with state or action.
View Replies
View Related
Jun 1, 2014
Basically, it's to write a method that takes in, and then returns another array, whose first element is the average of the first two numbers, last element is the average of the last two, and then everything else is just the average of that index, the one before, and the one after. {1, 2, 4, 8} would return {1.5, 2.33333, 4.66666, 6}.I'm currently getting everything fine, except am not getting the last number (i.e. '6').
public class Arrays {
public static void main(String [] args){
double [] a1 = {1, 2, 4, 8};
for (int i = 0; i < a1.length; i++)
System.out.println(a1[i]);
[code]....
View Replies
View Related