Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 根据用户在android设置中的选择设置ImageView_Java_Android_Android Imageview - Fatal编程技术网

Java 根据用户在android设置中的选择设置ImageView

Java 根据用户在android设置中的选择设置ImageView,java,android,android-imageview,Java,Android,Android Imageview,我正在尝试制作一个应用程序,该应用程序将根据用户在我的应用程序设置中选择的ListPreference更改图像。有两幅画,一片森林和一片海洋。当选择Ocean时,发送到字符串的值是1,对于林,发送到字符串的值是2,但是当我运行此代码时,它会抛出一个错误,显示“Source not found”。有任何迹象吗 public void showUserSettings() { String name; String pic; SharedPreferences sha

我正在尝试制作一个应用程序,该应用程序将根据用户在我的应用程序设置中选择的ListPreference更改图像。有两幅画,一片森林和一片海洋。当选择Ocean时,发送到字符串的值是1,对于林,发送到字符串的值是2,但是当我运行此代码时,它会抛出一个错误,显示“Source not found”。有任何迹象吗

 public void showUserSettings() {
     String name;
     String pic;
     SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
     name = sharedPrefs.getString("your_name", "NULL");
     pic = sharedPrefs.getString("pic_what", "for");
     int whatPic = Integer.parseInt(pic);
     TextView tvName = (TextView) findViewById(R.id.tvName);
     tvName.setText(name);
     if(whatPic==1) {
              ImageView img = (ImageView) findViewById(R.id.iView);
             img.setImageResource(R.drawable.ocean);
     }else if(whatPic==2); {
         ImageView img = (ImageView) findViewById(R.id.iView);
         img.setImageResource(R.drawable.forest);    
     }

 }

}

发布准确的错误。这就是错误。“未找到源”和用于设置源所在位置的按钮。