在我的android项目中在图像视图中显示pic时发现源未找到错误

时间:2012-03-19 09:34:00

标签: android

package your.Ui.PickImage;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class PickImageActivity extends Activity  implements View.OnClickListener
{
    Button button1, button2;
    ImageView yourimgView=(ImageView)findViewById(R.id.imageView1);
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        button1 = (Button) findViewById(R.id.button1);
        button2 = (Button) findViewById(R.id.button2);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
    }



    public void onClick(View v) 
    {
        switch(v.getId()) 
        {
            case R.id.button1:
                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                photoPickerIntent.setType("image/*");
                startActivityForResult(photoPickerIntent, 1);
            break;
            case R.id.button2:
                Toast.makeText(this, "sorry..!!!cannot access download file..!!!", 

                      Toast.LENGTH_LONG).show();

            break;
       }
    }
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
        case 1:
         {
          if (resultCode == RESULT_OK)
          {
            Uri photoUri = data.getData();
            if (photoUri != null)
            {
            try {
                  String[] filePathColumn = {MediaStore.Images.Media.DATA};
                  Cursor cursor = getContentResolver().query(photoUri, 

                       filePathColumn, null, null, null); 
                 cursor.moveToFirst();
                  int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                  String filePath = cursor.getString(columnIndex);
                  cursor.close();
                  Bitmap bMap = BitmapFactory.decodeFile(filePath);
                  yourimgView.setImageBitmap(bMap);

         }catch(Exception e)
          {}
          }
        }
        }
        }}
}

我正在使用这段代码搜索图库中的图片并在图片视图上显示该图片。在加载应用程序时,我收到了找不到源的错误,我应该编辑源查找路径。我现在该怎么办?

0 个答案:

没有答案