2D ArrayList索引超出界限(2D ArrayList Index Out of Bounds)
我正在为我的APP实现2D数组。
但不幸的是我有这个错误。FATAL EXCEPTION: main Process: com.application.recast, PID: 18534 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.application.recast/com.application.recast.SplashScreen}: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at java.util.ArrayList.get(ArrayList.java:411) at com.application.recast.SplashScreen.onCreate(SplashScreen.java:60) at android.app.Activity.performCreate(Activity.java:6664) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
我正在做的是,我想将特定项目存储到2D数组的特定索引中。
相当新的2D arraylist。
这是我的代码。ArrayList<String> mStrings = new ArrayList<>(); ArrayList<ArrayList<String>> list = new ArrayList<>(); mStrings.add("HI"); mStrings.add("HI2"); mStrings.add("HI3"); mStrings.add("HI4"); list.add(0,mStrings); for(int x=0;x<list.size();x++){ for(int y=0;y<mStrings.size();y++){ Log.d("VALUE",String.valueOf(list.get(y))); } }
I was implementing 2D Array for my APP.
But unfortunately I had this error.FATAL EXCEPTION: main Process: com.application.recast, PID: 18534 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.application.recast/com.application.recast.SplashScreen}: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at java.util.ArrayList.get(ArrayList.java:411) at com.application.recast.SplashScreen.onCreate(SplashScreen.java:60) at android.app.Activity.performCreate(Activity.java:6664) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
What I am doing is that, I want to store specific item into specific index of 2D array.
Pretty new with 2D arraylist.
Here's my code.ArrayList<String> mStrings = new ArrayList<>(); ArrayList<ArrayList<String>> list = new ArrayList<>(); mStrings.add("HI"); mStrings.add("HI2"); mStrings.add("HI3"); mStrings.add("HI4"); list.add(0,mStrings); for(int x=0;x<list.size();x++){ for(int y=0;y<mStrings.size();y++){ Log.d("VALUE",String.valueOf(list.get(y))); } }
原文:https://stackoverflow.com/questions/42688699
最满意答案
典型的风格是做这样的事情:
traverseDirectory :: RawFilePath -> (InputStream RawFilePath -> IO a) -> IO a
即标准的“with-”功能,具有明显的实现。
编辑 :添加了一个工作示例实现: https : //gist.github.com/gregorycollins/00c51e7e33cf1f9c8cc0
它并不完全复杂,但它也不像我最初建议的那样微不足道。
Typical style would be to do something like this:
traverseDirectory :: RawFilePath -> (InputStream RawFilePath -> IO a) -> IO a
i.e. a standard "with-" function, with the obvious implementation.
Edit: added a working example implementation: https://gist.github.com/gregorycollins/00c51e7e33cf1f9c8cc0
It's not exactly complicated but it's also not as trivial as I had first suggested.
相关问答
更多-
您可以检测当前目录何时更改以及是否超出限制,将目录设置回限制目录。 您可以通过执行非阻塞对话框,并将QFileDialog::directoryEntered(const QString& directory)信号连接到您自己可以进行检查的插槽来完成此操作。 如果检查失败,请通过QFileDialog::setDirectory(const QString& directory)将当前目录设置为限制目录。 免责声明我没有试过这个,但如果它不起作用我会感到惊讶。 You can detect when the ...
-
典型的风格是做这样的事情: traverseDirectory :: RawFilePath -> (InputStream RawFilePath -> IO a) -> IO a 即标准的“with-”功能,具有明显的实现。 编辑 :添加了一个工作示例实现: https : //gist.github.com/gregorycollins/00c51e7e33cf1f9c8cc0 它并不完全复杂,但它也不像我最初建议的那样微不足道。 Typical style would be to do somet ...
-
目录遍历攻击(Directory traversal attacks)[2023-02-02]
如果服务器设置为阻止../但无法使用..\阻止目录遍历,则可以绕过环境卫生。 您可能需要替换更多斜杠或不同的组合; 我肯定会尝试..%5C..%5C之前..%5C../ 。 If the server is set up to block ../ but fails to block directory traversals using ..\, you could bypass sanitation. You might have to replace more slashes, or a differe ... -
由于Guid是唯一传入的东西,并且Guid不能形成..\..\ ,我认为你对目录遍历攻击是安全的。 唯一的其他输入是ConfigurationManager.AppSettings["LogFilePath"] 。 这可以是X:\Example\..的形式,但它也可以是X:\ ,所以我不认为这是一个问题。 无论哪种方式,您都会将@"\ErrorLogs\Logs\"到您正在编写的路径中。 我也建议使用Path.Combine ,所以你不必迷路了 string varpath = Path.Combine(C ...
-
我相信你正在寻找的旗帜是--notebook-dir=/home/foo/wherever 。 我通过运行ipython notebook --help找到了这个。 不幸的是,在服务器运行时浏览目录仍然“即将来临”。 这是需要以正确方式完成的事情之一,能够做到这一点的人(不包括我)相当忙碌。 I believe the flag you're looking for is --notebook-dir=/home/foo/wherever. I found this by running ipython n ...
-
Ruby中的目录遍历(Directory Traversal in Ruby)[2024-03-07]
问题是每次你递归时,你传递给File.directory?的路径File.directory? 不是只是实体(文件或目录)的名称; 所有上下文都会丢失。 因此,假设你进入one/two/three/来检查one/two/three/file.txt是否是一个目录File.directory? 只是从顶层目录的角度,将"file.txt"作为路径而不是整个事物。 每次你递归时你都必须保持相对路径。 这似乎工作正常: def walk(start) Dir.foreach(start) do |x| ... -
好吧,如果允许用户登录,则不可能避免强制使用文件名。 但是,对于未登录的用户,如果用户未登录,则可以返回404状态代码。 另外,当有浏览器插件允许您发送任何请求时,为什么要使用URL重写。 Well, no it isn't possible to avoid bruteforcing file names, if the user is allowed to login. For not logged in users you could return a 404 status code if the u ...
-
如何使用ThreadPoolExecutor递归遍历目录?(How to recursive traversal directory using ThreadPoolExecutor?)[2022-09-05]
代码中有一个死锁。 当您使用ThreadPoolExecutor(4) ,此执行程序中只有四个工作线程,因此您不能同时运行四个以上的任务。 想象以下最简单的结构: test ----script.py ----test1 --------test2 ------------test3 ----------------test4 --------------------test5 如果python script.py ,第一个工作线程处理test1 ,第二个处理test1/test2 ,第三个处理test1 ... -
System.IO.Directory.Exists()与Windows和Linux一起使用(System.IO.Directory.Exists() use with both Windows and Linux)[2023-04-04]
Windows对此非常宽容。 你可以使用正斜杠,它会理解。 如果你不想冒险,可能会感到困惑(我不是100%肯定Windows 总是理解这一点),你可以使用Path.DirectorySeparatorChar Windows is quite tolerant about this. You can use the forward slash and it will understand. If you don't want to take the chance it might get confused ... -
我会说你可以肯定这是不可能的,然后我尝试了,我不得不说,不,似乎http模块不会删除'/../'。 您看到的重定向是在浏览器中完成的。 因此,它是否存在安全风险取决于您的静态处理程序的实现方式。 概念证明: // Server var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end(req.url); ...