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 String hexStringToString(String input) {
    try {/*  w  ww  .j  ava 2s .  com*/
        return hexStringToString(input, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("UTF-8 encoding is not supported by JVM");
    }
}

From source file:Main.java

public static JDialog getOnlyVisibleDialog(Window owner) {
    JDialog d = null;//from www  .j  av  a  2s. co m
    for (Window w : Window.getWindows()) {
        //         System.out.println("found " + w + " " + w.getOwner());
        if (w instanceof JDialog && w.isShowing() && ((JDialog) w).getOwner() == owner) {
            if (d != null)
                throw new IllegalStateException("num dialogs > 1");
            d = (JDialog) w;
        }
    }
    return d;
}

From source file:Main.java

public static Class<?> inClassPath(@NonNull String clsName) {
    try {//  www.  j  a v a2 s . co  m
        return Class.forName(clsName);
    } catch (Throwable t) {
        throw new IllegalStateException(String
                .format("%s is not in your class path! You must include the associated library.", clsName));
    }
}

From source file:Main.java

public static void consumeStart(XMLStreamReader xmlRdr, String elementName) throws XMLStreamException {
    while (xmlRdr.hasNext()) {
        if (xmlRdr.isStartElement() && xmlRdr.getLocalName().equals(elementName)) {
            xmlRdr.next();//from  ww w  .  j  a  v a2  s. co  m
            return;
        }
        xmlRdr.next();
    }
    throw new IllegalStateException(
            "expected start tag <" + elementName + ">, found '" + xmlRdr.getText() + "'");
}

From source file:Main.java

public static Activity getActivity(View view) {
    Context context = view.getContext();
    while (!(context instanceof Activity)) {
        if (context instanceof ContextWrapper) {
            context = ((ContextWrapper) context).getBaseContext();
        } else {//from www.  jav a 2 s .c om
            throw new IllegalStateException("Got a context of class " + context.getClass()
                    + " and I don't know how to get the Activity from it");
        }
    }
    return (Activity) context;
}

From source file:Main.java

public static boolean setProperty(Object object, String fieldName, Object fieldValue) {
    Class<?> clazz = object.getClass();
    String mname = "set" + fieldName;
    try {/*w  w w  .j a v  a 2 s  .  c om*/
        for (Method m : clazz.getMethods()) {
            if (m.getName().equalsIgnoreCase(mname)) {
                m.invoke(object, fieldValue);
                return true;
            }
        }
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }

    return false;
}

From source file:Main.java

public static ArrayList<Node> findAllChildren(final Node n, final String name) {
    final ArrayList<Node> retVal = new ArrayList<Node>();
    for (int i = 0; i < n.getChildNodes().getLength(); i++) {
        if (n.getChildNodes().item(i).getNodeName().equals(name)) {
            retVal.add(n.getChildNodes().item(i));
        }//from  w w w .jav a 2 s.c  om
    }
    if (retVal.isEmpty()) {
        throw new IllegalStateException("no " + name + " children found in: " + n.getNodeName());
    }
    return retVal;
}

From source file:Main.java

public static File getConfigFile(final String filename) {
    final File configFolder = new File(Environment.getExternalStorageDirectory(), CARDBOARD_CONFIG_FOLDER);
    if (!configFolder.exists()) {
        configFolder.mkdirs();//from w  ww.j  av  a 2 s .  c  o m
    } else if (!configFolder.isDirectory()) {
        final String value = String.valueOf(String.valueOf(configFolder));
        throw new IllegalStateException(
                new StringBuilder().append("Folder ").append(value).append(" already exists").toString());
    }
    return new File(configFolder, filename);
}

From source file:Main.java

public static void exit(final XmlPullParser pp) throws XmlPullParserException, IOException {
    exitSkipToEnd(pp);//  w w  w .  j  a v a2  s  .c o  m

    if (pp.getEventType() != XmlPullParser.END_TAG)
        throw new IllegalStateException("expecting end tag to exit");

    pp.next();
}

From source file:Main.java

@NonNull
public static Activity unwrapActivity(@NonNull Context startFrom) {
    while (startFrom instanceof ContextWrapper) {
        if (startFrom instanceof Activity) {
            return ((Activity) startFrom);
        }//www .j  a  va 2  s  . c o  m
        startFrom = ((ContextWrapper) startFrom).getBaseContext();
    }
    throw new IllegalStateException("This Context can't be unwrapped to an Activity!");
}