线程中的异常" main

时间:2018-01-18 03:50:35

标签: java

我是Java的新手(或者为了简单起见,使用任何编程语言),这就是我写的内容;

const post = database.database().ref("/redux-todo/");
    let obj={
            value
        }
    let request = post.push(obj)
    console.log(request.val());

此代码导致以下错误; 线程" main"中的例外情况java.lang.ArrayIndexOutOfBoundsException:0     在Sample.main(Sample.java:5)

  

有人可以帮助我在这里犯错误导致它抛出错误吗?

5 个答案:

答案 0 :(得分:1)

尝试使用参数运行应用程序。如果您是从终端运行它,则可以java MyApp 4执行此操作,其中MyApp是您的应用名称,4是您的参数。

如果您使用的是IDE,请查看运行配置。

如果您希望在应用程序运行后从用户那里获取输入,请查看堆栈溢出时的question

不要放弃。你将会喜欢Java,以掌握基础知识。

答案 1 :(得分:0)

当您尝试执行此代码时,您应该传递参数。

如果您通过命令行执行此代码,请尝试以下操作:

java YourClassName 25

如果您使用的是Eclipse或IntelliJ或NetBeans等IDE,请参阅以下链接:

Adding args on Eclipse

Adding args on IntelliJ

如果没有传递参数,args数组的长度为0,并且当您说args[0]不存在时,您正试图访问第一个元素。这就是它抛出异常的原因。

答案 2 :(得分:0)

你可能没有将月份作为程序参数传递。一旦你这样做就应该有效。

如果在命令行上运行它,则需要在命令中的类名后面提供它。 IDE具有用于运行配置的UI屏幕,可接受程序参数。

答案 3 :(得分:0)

首先,你错误地初始化了数组,这是初始化12大小的整数数组的方法之一。

month

然后你得到的错误是由于越界,意味着程序找不到错误初始化变量中的下一个整数if(args.length!= 0){ //do this month = Integer.parseInt(args[0]); //... }else{ System.out.println("Wrong input entered"); }

  

月数组索引也以0开头,结束时大小为11   12

意思是它可以存储12个编号从0到11的东西。 希望它能帮助您更好地理解数组。 :d

编辑: 确保在运行程序时传入了一个数字。 否则你可以做一个if语句来检查args是否为空

<?xml version="1.0" encoding="UTF-8"?>
<call number="+91234567890" duration="49" date="1483514046018" type="3" 
 presentation="1" readable_date="04-Jan-2017 12:44:06 PM" 
    contact_name="Dad" />

答案 4 :(得分:0)

如果您尝试获取当月的用户输入,则需要使用扫描仪。如果是这种情况,您需要------ Rebuild All started: Project: ****.Pipeline.Usql, Configuration: Debug Any CPU ------ Clean U-SQL Application Temporary Folder. Building Script: ParseHourlyCSVToTable.usql D:\src\GitHub\****\WebApp\****.Pipeline.USql\ParseHourlyCSVToTable.usql(1,0): error External0: Unexpected Exception 'System.IO.IOException: The process cannot access the file 'D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll' because it is being used by another process. Server stack trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost) at ScopeCompiler.Parser.CopyFileIfDifferent(String sourceDirPath, String sourceFileName, String destDirPath, String destFileName) at Microsoft.Analytics.LocalRun.LocalParseSandboxer.CloneLocalRuntimeFiles(Configuration config, Settings settings) at Microsoft.Analytics.LocalRun.LocalParseSandboxer.PrivateParse(String script, Settings settings) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Microsoft.Analytics.LocalRun.LocalParseSandboxer.PrivateParse(String script, Settings settings) at Microsoft.Analytics.LocalRun.LocalParseSandboxer.CompileInSeparateAppDomain(String[] scripts, Settings settings, Configuration configuration) at ScopeCompiler.Parser.FullParse(String[] scripts, String filePath, CompilerEnvironment environment, Settings settings, Func`4 funcParse, String nebulaCommandLine) at Microsoft.Analytics.LocalRun.LocalParseSandboxer.FullParseInSeparateAppDomain(String script, String filePath, Settings settings, Configuration configuration) at Microsoft.Analytics.LocalRun.LocalCompiler.Compile(String script, String filePath, Boolean shallow, CommonCompileResult& result) at Microsoft.Analytics.LocalRun.LocalRunCompileService.Compile(CompileParameter parm)' Done building project "***.Pipeline.Usql.usqlproj" -- FAILED. ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== 导入它,然后声明扫描仪。为此,请键入7:45:34.6944917 AM LocalRunHelper.exe 3036 CreateFileMapping D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS SyncType: SyncTypeOther 7:45:34.6945669 AM LocalRunHelper.exe 3036 CreateFileMapping D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll FILE LOCKED WITH ONLY READERS SyncType: SyncTypeCreateSection, PageProtection: PAGE_EXECUTE_READ|PAGE_NOCACHE 7:45:34.6945884 AM LocalRunHelper.exe 3036 QueryStandardInformationFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS AllocationSize: 1,048,576, EndOfFile: 112,088, NumberOfLinks: 1, DeletePending: False, Directory: False 7:45:34.6947109 AM LocalRunHelper.exe 3036 CreateFileMapping D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS SyncType: SyncTypeOther 7:45:34.6947919 AM LocalRunHelper.exe 3036 CloseFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS 7:45:48.2407503 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS Desired Access: Write Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened 7:45:48.2407875 AM LocalRunHelper.exe 3036 SetBasicInformationFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS CreationTime: 0, LastAccessTime: 0, LastWriteTime: 0, ChangeTime: 0, FileAttributes: N 7:45:48.2408299 AM LocalRunHelper.exe 3036 CloseFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS 7:45:48.2409359 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS Desired Access: Read Attributes, Delete, Disposition: Open, Options: Non-Directory File, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened 7:45:48.2409958 AM LocalRunHelper.exe 3036 QueryAttributeTagFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll INVALID PARAMETER 7:45:48.2410173 AM LocalRunHelper.exe 3036 SetDispositionInformationFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll CANNOT DELETE Delete: True 7:45:48.2410430 AM LocalRunHelper.exe 3036 CloseFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS 7:45:48.3611876 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened 7:45:48.3612181 AM LocalRunHelper.exe 3036 QueryNetworkOpenInformationFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS CreationTime: 1/26/2018 7:45:34 AM, LastAccessTime: 1/26/2018 7:45:34 AM, LastWriteTime: 1/11/2018 7:47:58 AM, ChangeTime: 1/1/1980 12:00:00 AM, AllocationSize: 1048576, EndOfFile: 112088, FileAttributes: N 7:45:48.3612365 AM LocalRunHelper.exe 3036 CloseFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS 7:45:48.3616927 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened 7:45:48.3617464 AM LocalRunHelper.exe 3036 QueryNetworkOpenInformationFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS CreationTime: 1/26/2018 7:45:34 AM, LastAccessTime: 1/26/2018 7:45:34 AM, LastWriteTime: 1/11/2018 7:47:58 AM, ChangeTime: 1/1/1980 12:00:00 AM, AllocationSize: 1048576, EndOfFile: 112088, FileAttributes: N 7:45:48.3617645 AM LocalRunHelper.exe 3036 CloseFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS 7:45:48.3618907 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS Desired Access: Write Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened 7:45:48.3619236 AM LocalRunHelper.exe 3036 SetBasicInformationFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS CreationTime: 0, LastAccessTime: 0, LastWriteTime: 0, ChangeTime: 0, FileAttributes: N 7:45:48.3619495 AM LocalRunHelper.exe 3036 CloseFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SUCCESS 7:45:48.3623476 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SHARING VIOLATION Desired Access: Generic Read/Write, Delete, Write DAC, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Attributes: A, ShareMode: None, AllocationSize: 112,088 7:45:48.3624410 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SHARING VIOLATION Desired Access: Generic Write, Read Data/List Directory, Read Attributes, Delete, Write DAC, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Attributes: A, ShareMode: None, AllocationSize: 112,088 7:45:48.3625282 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SHARING VIOLATION Desired Access: Generic Write, Read Attributes, Delete, Write DAC, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Attributes: A, ShareMode: None, AllocationSize: 112,088 7:45:48.3626137 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SHARING VIOLATION Desired Access: Generic Write, Read Data/List Directory, Read Attributes, Delete, Write DAC, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Attributes: A, ShareMode: Read, Write, AllocationSize: 112,088 7:45:48.3627039 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SHARING VIOLATION Desired Access: Generic Write, Read Data/List Directory, Read Attributes, Delete, Write DAC, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Attributes: A, ShareMode: Read, Write, AllocationSize: 112,088 7:45:48.3627877 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SHARING VIOLATION Desired Access: Generic Write, Read Attributes, Delete, Write DAC, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Attributes: A, ShareMode: Read, Write, AllocationSize: 112,088 7:45:48.3628705 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SHARING VIOLATION Desired Access: Generic Write, Read Data/List Directory, Read Attributes, Write DAC, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Attributes: A, ShareMode: Read, Write, AllocationSize: 112,088 7:45:48.3629550 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SHARING VIOLATION Desired Access: Generic Write, Read Data/List Directory, Read Attributes, Write DAC, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Attributes: A, ShareMode: Read, Write, AllocationSize: 112,088 7:45:48.3630398 AM LocalRunHelper.exe 3036 CreateFile D:\src\GitHub\****\WebApp\****.Pipeline.USql\bin\Debug\ParseHourlyCSVToTable\Microsoft.Analytics.LocalRun.dll SHARING VIOLATION Desired Access: Generic Write, Read Attributes, Write DAC, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Attributes: A, ShareMode: Read, Write, AllocationSize: 112,088 。 “System.in”是您的输入,在这种情况下是键盘。然后你可以import java.util.Scanner;来获取键盘上输入的下一个整数。

如果我对您要做的事情不正确,请发送评论,我会编辑我的帖子并尝试进一步帮助您。干杯!