首页 \ 问答 \ 2D ArrayList索引超出界限(2D ArrayList Index Out of Bounds)

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
更新时间:2023-03-24 17:03

最满意答案

典型的风格是做这样的事情:

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 ...
  • 如果服务器设置为阻止../但无法使用..\阻止目录遍历,则可以绕过环境卫生。 您可能需要替换更多斜杠或不同的组合; 我肯定会尝试..%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 ...
  • 问题是每次你递归时,你传递给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(4) ,此执行程序中只有四个工作线程,因此您不能同时运行四个以上的任务。 想象以下最简单的结构: test ----script.py ----test1 --------test2 ------------test3 ----------------test4 --------------------test5 如果python script.py ,第一个工作线程处理test1 ,第二个处理test1/test2 ,第三个处理test1 ...
  • 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); ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)