美好的一天
我试图将gridview中捕获的图像传递给另一个活动,这样我就可以全屏显示它。问题是当我点击gridview中的一个项目时,应用程序就是粉碎.. 任何帮助将不胜感激
这是代码 相机片段
public class CameraFragment extends Fragment {
Images images;
byte[] image1;
DatabaseAdapter databaseAdapter;
private ImageListAdapter adapter;
private List<Images> myLists;// image list
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_camera, container, false);
databaseAdapter =new DatabaseAdapter(getActivity());
databaseAdapter.open();
myLists = new ArrayList<Images>();
myLists =databaseAdapter.getImagesList();
adapter = new ImageListAdapter(getActivity(), R.layout.img_list_view, myLists);
myGridView = (GridView) view.findViewById(R.id.gridView);
myGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Images selectedItem = (Images ) myLists.get(position);
image1=selectedItem.getImageBlob();
Intent intent = new Intent(getActivity(),DisplayImage.class);
intent.putExtra("image1",image1);
startActivity(intent);
Log.w(TAG, "image Blob" + image1 );
}
});
myGridView.setAdapter(adapter);
// Inflate the layout for this fragment
Button myButton = (Button) view.findViewById(R.id.camerabutton);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
显示图片活动
public class DisplayImage extends AppCompatActivity {
DatabaseAdapter databaseAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_invoice_image);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
databaseAdapter =new DatabaseAdapter(this);
databaseAdapter.open();
Intent i = getIntent();
ImageView imageView =(ImageView) findViewById(R.id.DisplayFull);
String image1 = i.getStringExtra("image1");
imageView.setImageBitmap(BitmapFactory.decodeFile(i.getStringExtra(image1)));
这里是logcat
Key image1 expected String but value was a [B. The default value <null> was returned.
06-08 07:44:25.251 10752-10752/com.example.labon.invoicemanger W/Bundle: Attempt to cast generated internal exception:
java.lang.ClassCastException: byte[] cannot be cast to java.lang.String
at android.os.BaseBundle.getString(BaseBundle.java:923)
at android.content.Intent.getStringExtra(Intent.java:5349)
at com.example.labon.invoicemanger.DisplayImage.onCreate(DisplayImage.java:36)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-08 07:44:25.251 10752-10752/com.example.labon.invoicemanger E/BitmapFactory: Unable to decode stream: java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
06-08 07:44:25.395 10752-10777/com.example.labon.invoicemanger W/EGL_emulation: eglSurfaceAttrib not implemented