小编Jos*_*ung的帖子

android使用Java中的for循环遍历按钮id

对于我正在处理的应用,我在活动上有几个按钮.

我有每个存储在数组中的文本(数据可以更改),我试图用for循环更新所有这些.

Id是button1,button2和button3

这就是我要的

for(int i=1; i<=splitter.length; i++){
        Button button = (Button)findViewById(R.id.button[i]);//<---How do i make this work

button.setText(spliter[i-1]);
    }
Run Code Online (Sandbox Code Playgroud)

java android

3
推荐指数
2
解决办法
3387
查看次数

为什么我会收到 NullPointerException?bufferWriter.close()

我是新手,但我正在编写一个应用程序,我不断收到此错误,导致应用程序在启动时崩溃。

java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.BufferedWriter.close()' on a null object reference
Run Code Online (Sandbox Code Playgroud)

导致它的代码在下面的类中,问题所在行旁边会有一个 HERE 注释。

public class FileOptions extends Activity{

public void createFile(String title, String storeValue){
    BufferedWriter bufferWriter = null;
    try {
        FileOutputStream fileOutputStream = openFileOutput(title, Context.MODE_PRIVATE);
        bufferWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream));

        String content = storeValue;

        bufferWriter.write(content);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    catch (IOException e) {  //Cannot be removed
        e.printStackTrace();
    }
    finally {
        try {
       /**HERE*/ bufferWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

} …
Run Code Online (Sandbox Code Playgroud)

java android

0
推荐指数
1
解决办法
3574
查看次数

比较lisp中的数字和列表对象

我是lisp的新手,所以如果我提前说这是一个简单的问题,我道歉.

我有一个清单:

(set ‘inventory ‘(parts
                   ((item 1001) (shoes (color brown) (size 10) (cost 20))) 
                   ((item 2011) (skirt (color blue) (size 4) (cost 10)))
                   ((item 2120) (pants (color white) (size 32) (cost 30)))
                   ((item 2121) (pants (color brown) (size 34) (cost 30)))))
Run Code Online (Sandbox Code Playgroud)

我正在尝试编写一个按项目编号查看列表的函数,并返回正确的函数.

(findItem 1001 inventory) 应该返回:

((item 1001) (shoes (color brown) (size 10) (cost 20)))
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止:

(defun findItem (q i)   
    (cond
        ((null q)
         nil)
        ((null (cdr i))
         nil)
        ((eq `parts (car i))
         (findItem q (cdr i)))
        ((eq q (cdr (car …
Run Code Online (Sandbox Code Playgroud)

lisp

0
推荐指数
1
解决办法
296
查看次数

标签 统计

android ×2

java ×2

lisp ×1