Example usage for java.lang NullPointerException NullPointerException

List of usage examples for java.lang NullPointerException NullPointerException

Introduction

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

Prototype

public NullPointerException(String s) 

Source Link

Document

Constructs a NullPointerException with the specified detail message.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    try {//from  w  ww  . j av a 2 s .  co m
        throw new NullPointerException("demo");
    } catch (NullPointerException e) {
        System.out.println("recaught: " + e);
        e.printStackTrace();
    }
}

From source file:com.github.aliteralmind.codelet.examples.non_xbn.PrintJDBlocksStartStopLineNumsXmpl.java

/**
   <p>The main function.</p>
 *///from  w  w w  . ja v a  2s.c o  m
public static final void main(String[] as_1RqdJavaSourcePath) {

    //Read command-line parameter
    String sJPath = null;
    try {
        sJPath = as_1RqdJavaSourcePath[0];
    } catch (ArrayIndexOutOfBoundsException aibx) {
        throw new NullPointerException(
                "Missing one-and-only required parameter: Path to java source-code file.");
    }
    System.out.println("Java source: " + sJPath);

    //Establish line-iterator
    Iterator<String> lineItr = null;
    try {
        lineItr = FileUtils.lineIterator(new File(sJPath)); //Throws npx if null
    } catch (IOException iox) {
        throw new RTIOException("PrintJDBlocksStartStopLinesXmpl", iox);
    }
    Pattern pTrmdJDBlockStart = Pattern.compile("^[\\t ]*/\\*\\*");

    String sDD = "..";
    int lineNum = 1;
    boolean bInJDBlock = false;
    while (lineItr.hasNext()) {
        String sLn = lineItr.next();
        if (!bInJDBlock) {
            if (pTrmdJDBlockStart.matcher(sLn).matches()) {
                bInJDBlock = true;
                System.out.print(lineNum + sDD);
            }
        } else if (sLn.indexOf("*/") != -1) {
            bInJDBlock = false;
            System.out.println(lineNum);
        }
        lineNum++;
    }
    if (bInJDBlock) {
        throw new IllegalStateException("Reach end of file. JavaDoc not closed.");
    }
}

From source file:com.morty.podcast.writer.validation.StandardFileValidator.java

public static void main(String[] args) {
    //Process a directory without exclusion...
    Log m_logger = LogFactory.getLog(StandardFileValidator.class);
    m_logger.info("Starting Validator");

    if (args.length != 1)
        throw new NullPointerException("No directory specified");

    String fileToProcess = args[0];
    m_logger.info("Processing [" + fileToProcess + "]");
    StandardFileValidator sfv = new StandardFileValidator();
    sfv.setFolderToProcess(new File(fileToProcess));
    try {//from  w ww  .  ja  v  a  2 s  . c o  m
        sfv.process();
        m_logger.info("Directory Valid");
    } catch (Exception ex) {
        m_logger.info("Directory InValid");
        m_logger.error("Error thrown", ex);
    }

    m_logger.info("Finished Validator");
}

From source file:MailHandlerDemo.java

/**
 * Runs the demo./*from   w  w w  . jav a  2s  . c  om*/
 *
 * @param args the command line arguments
 * @throws IOException if there is a problem.
 */
public static void main(String[] args) throws IOException {
    List<String> l = Arrays.asList(args);
    if (l.contains("/?") || l.contains("-?") || l.contains("-help")) {
        LOGGER.info("Usage: java MailHandlerDemo " + "[[-all] | [-body] | [-custom] | [-debug] | [-low] "
                + "| [-simple] | [-pushlevel] | [-pushfilter] " + "| [-pushnormal] | [-pushonly]] " + "\n\n"
                + "-all\t\t: Execute all demos.\n" + "-body\t\t: An email with all records and only a body.\n"
                + "-custom\t\t: An email with attachments and dynamic names.\n"
                + "-debug\t\t: Output basic debug information about the JVM " + "and log configuration.\n"
                + "-low\t\t: Generates multiple emails due to low capacity." + "\n"
                + "-simple\t\t: An email with all records with body and " + "an attachment.\n"
                + "-pushlevel\t: Generates high priority emails when the"
                + " push level is triggered and normal priority when " + "flushed.\n"
                + "-pushFilter\t: Generates high priority emails when the "
                + "push level and the push filter is triggered and normal " + "priority emails when flushed.\n"
                + "-pushnormal\t: Generates multiple emails when the "
                + "MemoryHandler push level is triggered.  All generated "
                + "email are sent as normal priority.\n" + "-pushonly\t: Generates multiple emails when the "
                + "MemoryHandler push level is triggered.  Generates high "
                + "priority emails when the push level is triggered and " + "normal priority when flushed.\n");
    } else {
        final boolean debug = init(l); //may create log messages.
        try {
            LOGGER.log(Level.FINEST, "This is the finest part of the demo.",
                    new MessagingException("Fake JavaMail issue."));
            LOGGER.log(Level.FINER, "This is the finer part of the demo.",
                    new NullPointerException("Fake bug."));
            LOGGER.log(Level.FINE, "This is the fine part of the demo.");
            LOGGER.log(Level.CONFIG, "Logging config file is {0}.", getConfigLocation());
            LOGGER.log(Level.INFO, "Your temp directory is {0}, " + "please wait...", getTempDir());

            try { //Waste some time for the custom formatter.
                Thread.sleep(3L * 1000L);
            } catch (InterruptedException ex) {
                Thread.currentThread().interrupt();
            }

            LOGGER.log(Level.WARNING, "This is a warning.",
                    new FileNotFoundException("Fake file chooser issue."));
            LOGGER.log(Level.SEVERE, "The end of the demo.", new IOException("Fake access denied issue."));
        } finally {
            closeHandlers();
        }

        //Force parse errors.  This does have side effects.
        if (debug && getConfigLocation() != null) {
            LogManager.getLogManager().readConfiguration();
        }
    }
}

From source file:marytts.tools.analysis.CopySynthesis.java

/**
 * @param args/*  w  ww  .  ja  v a2  s  .  co  m*/
 */
public static void main(String[] args) throws Exception {
    String wavFilename = null;
    String labFilename = null;
    String pitchFilename = null;
    String textFilename = null;

    String locale = System.getProperty("locale");
    if (locale == null) {
        throw new IllegalArgumentException("No locale given (-Dlocale=...)");
    }

    for (String arg : args) {
        if (arg.endsWith(".txt"))
            textFilename = arg;
        else if (arg.endsWith(".wav"))
            wavFilename = arg;
        else if (arg.endsWith(".ptc"))
            pitchFilename = arg;
        else if (arg.endsWith(".lab"))
            labFilename = arg;
        else
            throw new IllegalArgumentException("Don't know how to treat argument: " + arg);
    }

    // The intonation contour
    double[] contour = null;
    double frameShiftTime = -1;
    if (pitchFilename == null) { // need to create pitch contour from wav file 
        if (wavFilename == null) {
            throw new IllegalArgumentException("Need either a pitch file or a wav file");
        }
        AudioInputStream ais = AudioSystem.getAudioInputStream(new File(wavFilename));
        AudioDoubleDataSource audio = new AudioDoubleDataSource(ais);
        PitchFileHeader params = new PitchFileHeader();
        params.fs = (int) ais.getFormat().getSampleRate();
        F0TrackerAutocorrelationHeuristic tracker = new F0TrackerAutocorrelationHeuristic(params);
        tracker.pitchAnalyze(audio);
        frameShiftTime = tracker.getSkipSizeInSeconds();
        contour = tracker.getF0Contour();
    } else { // have a pitch file -- ignore any wav file
        PitchReaderWriter f0rw = new PitchReaderWriter(pitchFilename);
        if (f0rw.contour == null) {
            throw new NullPointerException("Cannot read f0 contour from " + pitchFilename);
        }
        contour = f0rw.contour;
        frameShiftTime = f0rw.header.skipSizeInSeconds;
    }
    assert contour != null;
    assert frameShiftTime > 0;

    // The ALLOPHONES data and labels
    if (labFilename == null) {
        throw new IllegalArgumentException("No label file given");
    }
    if (textFilename == null) {
        throw new IllegalArgumentException("No text file given");
    }
    MaryTranscriptionAligner aligner = new MaryTranscriptionAligner();
    aligner.SetEnsureInitialBoundary(false);
    String labels = MaryTranscriptionAligner.readLabelFile(aligner.getEntrySeparator(),
            aligner.getEnsureInitialBoundary(), labFilename);
    MaryHttpClient mary = new MaryHttpClient();
    String text = FileUtils.readFileToString(new File(textFilename), "ASCII");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    mary.process(text, "TEXT", "ALLOPHONES", locale, null, null, baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    docFactory.setNamespaceAware(true);
    DocumentBuilder builder = docFactory.newDocumentBuilder();
    Document doc = builder.parse(bais);
    aligner.alignXmlTranscriptions(doc, labels);
    assert doc != null;

    // durations
    double[] endTimes = new LabelfileDoubleDataSource(new File(labFilename)).getAllData();
    assert endTimes.length == labels.split(Pattern.quote(aligner.getEntrySeparator())).length;

    // Now add durations and f0 targets to document
    double prevEnd = 0;
    NodeIterator ni = MaryDomUtils.createNodeIterator(doc, MaryXML.PHONE, MaryXML.BOUNDARY);
    for (int i = 0; i < endTimes.length; i++) {
        Element e = (Element) ni.nextNode();
        if (e == null)
            throw new IllegalStateException("More durations than elements -- this should not happen!");
        double durInSeconds = endTimes[i] - prevEnd;
        int durInMillis = (int) (1000 * durInSeconds);
        if (e.getTagName().equals(MaryXML.PHONE)) {
            e.setAttribute("d", String.valueOf(durInMillis));
            e.setAttribute("end", new Formatter(Locale.US).format("%.3f", endTimes[i]).toString());
            // f0 targets at beginning, mid, and end of phone
            StringBuilder f0String = new StringBuilder();
            double startF0 = getF0(contour, frameShiftTime, prevEnd);
            if (startF0 != 0 && !Double.isNaN(startF0)) {
                f0String.append("(0,").append((int) startF0).append(")");
            }
            double midF0 = getF0(contour, frameShiftTime, prevEnd + 0.5 * durInSeconds);
            if (midF0 != 0 && !Double.isNaN(midF0)) {
                f0String.append("(50,").append((int) midF0).append(")");
            }
            double endF0 = getF0(contour, frameShiftTime, endTimes[i]);
            if (endF0 != 0 && !Double.isNaN(endF0)) {
                f0String.append("(100,").append((int) endF0).append(")");
            }
            if (f0String.length() > 0) {
                e.setAttribute("f0", f0String.toString());
            }
        } else { // boundary
            e.setAttribute("duration", String.valueOf(durInMillis));
        }
        prevEnd = endTimes[i];
    }
    if (ni.nextNode() != null) {
        throw new IllegalStateException("More elements than durations -- this should not happen!");
    }

    // TODO: add pitch values

    String acoustparams = DomUtils.document2String(doc);
    System.out.println("ACOUSTPARAMS:");
    System.out.println(acoustparams);
}

From source file:Main.java

static void demoproc() {
    NullPointerException e = new NullPointerException("top layer");
    e.initCause(new ArithmeticException("cause"));
    throw e;/* www.j a  v a 2 s  .co  m*/
}

From source file:Main.java

static void aMethod() {
    try {/*from w  w w.  ja v a  2s  .  co  m*/
        throw new NullPointerException("demo");
    } catch (NullPointerException e) {
        System.out.println("Caught inside demoproc.");
        throw e; // rethrow the exception
    }
}

From source file:ChainExcDemo.java

static void demoproc() {
    NullPointerException e = new NullPointerException("top layer");

    e.initCause(new ArithmeticException("cause"));

    throw e;//from  w w  w.java2s.c o  m
}

From source file:Main.java

public static void throwException() {
    throw new NullPointerException("I am Exception");
}

From source file:Main.java

public static <T> void paramCheck(T t) {
    if (t == null) {
        throw new NullPointerException("param is null");
    }//from   w ww.jav  a2s  .c  o m
}