Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.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
android浏览图像_Android - Fatal编程技术网

android浏览图像

android浏览图像,android,Android,我正在安卓系统中做一个联系人列表项目,我想做一个浏览按钮来浏览一张图片,并将它保存在我的数据库中,然后我想在屏幕上显示图片。 你能给我一个很好的例子或教程,告诉我如何浏览图片并从数据库中保存/检索吗 对于begin,我试图让程序浏览图像,但我得到了一个错误 这是我的.java: package ianco.test.andrei; import android.app.Activity; import android.content.Intent; import android.

我正在安卓系统中做一个联系人列表项目,我想做一个浏览按钮来浏览一张图片,并将它保存在我的数据库中,然后我想在屏幕上显示图片。 你能给我一个很好的例子或教程,告诉我如何浏览图片并从数据库中保存/检索吗

对于begin,我试图让程序浏览图像,但我得到了一个错误

这是我的.java:

  package ianco.test.andrei;
  import android.app.Activity;
  import android.content.Intent;
  import android.database.Cursor;
  import android.net.Uri;
  import android.os.Bundle;
  import android.provider.MediaStore;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;

  public class BrowsePicture extends Activity {

//YOU CAN EDIT THIS TO WHATEVER YOU WANT
private static final int SELECT_PICTURE = 1;

private String selectedImagePath;
//ADDED
private String filemanagerstring;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);



   Button sButton = (Button) findViewById(R.id.button1);
   sButton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            // in onCreate or any event where your want the user to
            // select a file
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent,
                    "Select Picture"), SELECT_PICTURE);
        }
    });
}

//UPDATED
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();

            //OI FILE Manager
            filemanagerstring = selectedImageUri.getPath();

            //MEDIA GALLERY
            selectedImagePath = getPath(selectedImageUri);

            //DEBUG PURPOSE - you can delete this if you want
            if(selectedImagePath!=null)
                System.out.println(selectedImagePath);
            else System.out.println("selectedImagePath is null");
            if(filemanagerstring!=null)
                System.out.println(filemanagerstring);
            else System.out.println("filemanagerstring is null");

            //NOW WE HAVE OUR WANTED STRING
            if(selectedImagePath!=null)
                System.out.println("selectedImagePath is the right one for you!");
            else
                System.out.println("filemanagerstring is the right one for you!");
        }
    }
}

//UPDATED!
public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    if(cursor!=null)
    {
        //HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
        //THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
        int column_index = cursor
        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }
    else return null;
}
}

错误为:
12-24 00:14:07.742:E/AndroidRuntime(365):致命异常:main
12-24 00:14:07.742:E/AndroidRuntime(365):java.lang.RuntimeException:无法实例化活动组件信息{ianco.test.andrei/ianco.test.andrei.TestAgactivity}:java.lang.ClassNotFoundException:ianco.test.andrei.TestAgactivity装入器dalvik.system.PathClassLoader[/data/app/ianco.test.andrei-1.apk]
12-24 00:14:07.742:E/AndroidRuntime(365):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
12-24 00:14:07.742:E/AndroidRuntime(365):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-24 00:14:07.742:E/AndroidRuntime(365):在android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-24 00:14:07.742:E/AndroidRuntime(365):在android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-24 00:14:07.742:E/AndroidRuntime(365):在android.os.Handler.dispatchMessage(Handler.java:99)上
12-24 00:14:07.742:E/AndroidRuntime(365):在android.os.Looper.loop(Looper.java:123)上
12-24 00:14:07.742:E/AndroidRuntime(365):位于android.app.ActivityThread.main(ActivityThread.java:4627)
12-24 00:14:07.742:E/AndroidRuntime(365):位于java.lang.reflect.Method.Invokenactive(本机方法)
12-24 00:14:07.742:E/AndroidRuntime(365):位于java.lang.reflect.Method.invoke(Method.java:521)
12-24 00:14:07.742:E/AndroidRuntime(365):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-24 00:14:07.742:E/AndroidRuntime(365):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-24 00:14:07.742:E/AndroidRuntime(365):在dalvik.system.NativeStart.main(本机方法)
12-24 00:14:07.742:E/AndroidRuntime(365):由以下原因引起:java.lang.ClassNotFoundException:ianco.test.andrei.TestAction加载程序dalvik.system.PathClassLoader[/data/app/ianco.test.andrei-1.apk]
12-24 00:14:07.742:E/AndroidRuntime(365):位于dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
12-24 00:14:07.742:E/AndroidRuntime(365):在java.lang.ClassLoader.loadClass(ClassLoader.java:573)
12-24 00:14:07.742:E/AndroidRuntime(365):在java.lang.ClassLoader.loadClass(ClassLoader.java:532)
12-24 00:14:07.742:E/AndroidRuntime(365):在android.app.Instrumentation.newActivity(Instrumentation.java:1021)上
12-24 00:14:07.742:E/AndroidRuntime(365):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)

您的清单引用了一个不存在的
testa

00:14:07.742: E/AndroidRuntime(365): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ianco.test.andrei/ianco.test.andrei.TestareActivity}: java.lang.ClassNotFoundException: ianco.test.andrei.TestareActivity in loader dalvik.system.PathClassLoader[/data/app/ianco.test.andrei-1.apk]

修复清单或添加缺少的活动。

此活动是什么?