在Java中读取XML文件时出现非法参数异常

时间:2015-07-11 14:32:15

标签: java xml eclipse

我在关注视频教程的同时写了这篇文章。教程显示了同样的事情,但没有错误!

以下是代码:

public static void main(String[] args){

    DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder db = bf.newDocumentBuilder();

        //says input stream cannot be null
        Document d = db.parse(XmlReader.class.getResourceAsStream("XMLFile.xml")); 

        d.normalize();

当我运行程序时,它表示输入流对于语句指示语句不能为null,但是不是 null!。文件路径是正确的!有什么我想念的吗?是否存在eclipse或XML文件或其他问题?

堆栈跟踪:

Exception in thread "main" java.lang.IllegalArgumentException: InputStream cannot be null
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at io.XMLFileReading.main(XMLFileReading.java:27)

1 个答案:

答案 0 :(得分:1)

似乎使用 FileInputStream 可以完成这项工作(而不是XmlReader.class.getResourceAsStream())。

    NSNumber *compression = [NSNumber numberWithLong:900000];

    AVAsset *videoAsset = [[AVURLAsset alloc] initWithURL:inputURL options:nil];

    AVAssetTrack *videoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
    CGSize videoSize = videoTrack.naturalSize;
    NSDictionary *videoWriterCompressionSettings =  [NSDictionary dictionaryWithObjectsAndKeys:compression, AVVideoAverageBitRateKey, nil];
    NSDictionary *videoWriterSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecH264,
                                         AVVideoCodecKey, videoWriterCompressionSettings,
                                         AVVideoCompressionPropertiesKey, [NSNumber numberWithFloat:videoSize.width],
                                         AVVideoWidthKey, [NSNumber numberWithFloat:videoSize.height],
                                         AVVideoHeightKey, nil];

    AVAssetWriterInput* videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoWriterSettings];

    videoWriterInput.expectsMediaDataInRealTime = YES;

    videoWriterInput.transform = videoTrack.preferredTransform;

    AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:outputURL fileType:AVFileTypeQuickTimeMovie error:nil];

    [videoWriter addInput:videoWriterInput];

在此处查看类似问题和接受的答案:Cannot work with XML file. InputStream is null