Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.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 图像不';t载荷_Java_Android Studio_Imageview - Fatal编程技术网

Java 图像不';t载荷

Java 图像不';t载荷,java,android-studio,imageview,Java,Android Studio,Imageview,我一直在为用户在应用程序中将图片添加到其个人资料中的选项而努力。目前发生的情况如下: 您可以按默认图片,它将带您进入(在本例中)dropbox。然后您选择一张图片并将其加载(如果它工作的话,这会很漂亮)。出现的问题是,当我选择我想要的图片时,它应该加载到新的配置文件图片中。但是配置文件图片没有被我选择的图片替换。下面您将看到我在profile.class中使用的代码 包com.example.wilmar.rentacube.Profile import android.app.Activity

我一直在为用户在应用程序中将图片添加到其个人资料中的选项而努力。目前发生的情况如下:

您可以按默认图片,它将带您进入(在本例中)dropbox。然后您选择一张图片并将其加载(如果它工作的话,这会很漂亮)。出现的问题是,当我选择我想要的图片时,它应该加载到新的配置文件图片中。但是配置文件图片没有被我选择的图片替换。下面您将看到我在profile.class中使用的代码

包com.example.wilmar.rentacube.Profile

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.wilmar.rentacube.R;

/**
 * Created by wilmar on 23-4-2015.
 */
public class Profile extends Activity {

    ImageView contactImageImgView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profile);



        contactImageImgView = (ImageView) findViewById(R.id.imgViewContactImage);


        contactImageImgView.setOnClickListener(new View.OnClickListener() { // this is where the magic happens (or is supposed to)

            public void onClick (View v){  
                Intent intent = new Intent();
                intent.setType("image*/");
                intent.setAction(intent.ACTION_GET_CONTENT);
                startActivityForResult(intent.createChooser(intent, "Select Profile Image"), 1);
            }
        });

    }




// here should happen some more magic :)
    public void onActivityResult(int reqCode, int resCode, Intent data) {
        if(resCode == RESULT_OK){
            if(resCode == 1)
                contactImageImgView.setImageURI(data.getData());
        }

    }


} 
首先,这个

if(resCode == 1)
contactImageImgView.setImageURI(data.getData());
应该是

if( reqCode == 1)    //You used the wrong value here
contactImageImgView.setImageURI(data.getData());

此外,您可以向其发送意向的每个应用程序都将返回稍微不同的URI。您最好将其记录下来,看看是否没有“垃圾”附加。

修改URI后,您可以尝试使imageView失效()