Example usage for java.lang IllegalStateException IllegalStateException

List of usage examples for java.lang IllegalStateException IllegalStateException

Introduction

In this page you can find the example usage for java.lang IllegalStateException IllegalStateException.

Prototype

public IllegalStateException(Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:Main.java

public static void consumeEnd(XMLStreamReader xmlRdr, String elementName) throws XMLStreamException {
    while (xmlRdr.hasNext()) {
        if (xmlRdr.isEndElement() && xmlRdr.getLocalName().equals(elementName)) {
            xmlRdr.next();/*from  www  .  j a  v a2s  . com*/
            return;
        }
        xmlRdr.next();
    }
    throw new IllegalStateException(
            "expected start tag <" + elementName + ">, found '" + xmlRdr.getText() + "'");
}

From source file:Util.java

/**
 * Converts a java.awt.Image into an array of pixels
 *///from  w  w  w . j  a  va 2s . c  o  m
public static int[] convertToPixels(Image img) {
    int width = img.getWidth(null);
    int height = img.getHeight(null);
    int[] pixel = new int[width * height];

    PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, pixel, 0, width);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        throw new IllegalStateException("Error: Interrupted Waiting for Pixels");
    }
    if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
        throw new IllegalStateException("Error: Image Fetch Aborted");
    }
    return pixel;
}

From source file:Main.java

/**
 * Create a {@link Transformer} just the way we like it.
 *
 * @return Returns a new {@link Transformer}.
 *//*from w  w  w  .ja  v  a2s .  c  om*/
private static Transformer createTransformer() {
    final Transformer xform;
    try {
        xform = m_xformFactory.newTransformer();
    } catch (TransformerConfigurationException e) {
        throw new IllegalStateException(e);
    }
    xform.setOutputProperty(OutputKeys.INDENT, "yes");
    xform.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");
    xform.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    return xform;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <E> E getProperty(Object object, String fieldName) {
    Class<?> clazz = object.getClass();
    while (clazz != null) {
        try {/*from  w w w . j  av a  2s .co  m*/
            Field field = clazz.getDeclaredField(fieldName);
            field.setAccessible(true);
            return (E) field.get(object);
        } catch (NoSuchFieldException e) {
            clazz = clazz.getSuperclass();
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    return null;
}

From source file:Main.java

/**
 * @return a new document builder (never null)
 *//*from  w  w  w  .j a  va 2  s.  c om*/
public static final DocumentBuilder getDocumentBuilder() {
    // factory.setNamespaceAware(true);
    try {
        return factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException(e);
    }
}

From source file:Main.java

/**
 * @return a new document builder (never null)
 *///w w  w. j  a  v  a2 s . c o  m
public static DocumentBuilder getDocumentBuilder() {
    // factory.setNamespaceAware(true);
    try {
        return FACTORY.newDocumentBuilder();
    } catch (final ParserConfigurationException e) {
        throw new IllegalStateException(e);
    }
}

From source file:Main.java

public static void skipRestOfTree(final XmlPullParser pp) throws XmlPullParserException, IOException {
    if (pp.getEventType() != XmlPullParser.START_TAG && pp.getEventType() != XmlPullParser.END_TAG)
        throw new IllegalStateException(
                "expected START_TAG of parent or END_TAG of child:" + pp.getPositionDescription());

    while (true) {
        final int eventType = pp.next();

        if (eventType == XmlPullParser.START_TAG) {
            skipSubTree(pp);//from  w w  w . ja v  a2s  .  c om
            pp.require(XmlPullParser.END_TAG, null, null);
        } else if (eventType == XmlPullParser.END_TAG) {
            return;
        }
    }
}

From source file:Main.java

public static Object get(Context context, String name) {
    if (context == null || name == null) {
        throw new IllegalArgumentException("Context and key must not be null");
    }//from  w  ww  . ja  va2 s. co m
    Object systemService = context.getSystemService(name);
    if (systemService == null) {
        context = context.getApplicationContext();
        systemService = context.getSystemService(name);
    }
    if (systemService == null) {
        throw new IllegalStateException(name + " not available");
    }
    return systemService;
}

From source file:Main.java

public static String readAttributeValue(Element e, String attributeName) {
    if (!e.hasAttribute(attributeName)) {
        throw new IllegalStateException("Attribute '" + attributeName + "' is absent");
    }/*from  ww  w  . j  av a  2 s .co  m*/

    return e.getAttribute(attributeName);
}

From source file:Main.java

public static String text(final XmlPullParser pp) throws XmlPullParserException, IOException {
    if (pp.getEventType() != XmlPullParser.START_TAG || pp.isEmptyElementTag())
        throw new IllegalStateException("expecting start tag to get text from");

    enter(pp);//from w  w  w  . j ava  2  s  . com

    String text = "";
    if (pp.getEventType() == XmlPullParser.TEXT)
        text = pp.getText();

    exit(pp);

    return text;
}