开发者

grid view and shared preference android error

I am facing few problems while u开发者_如何学Pythonsing grid view and shared preference in android.

I am using grid view to get the image resource and pass the image resource to next activity to convert that to an image.

Activity A contains: code to convert resource image to image in EditText

Activity B contains: send image resource to Activity A (Select image from Gridview).

Activity A Code: code in this link: http://pastebin.com/AzUTEFWT

Activity B Code :code in this link: http://pastebin.com/cRp1vQan.

Please guide me in this issue.

I am able to diplay the gridview with images.

I get force close error when i select image in gridview


Ummm, I think I have find the problem. It's here:

 public void onItemClick(AdapterView parent,View arg1, int arg2, long arg3) {  
              //         public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                                // TODO Auto-generated method stub
                                SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
                                SharedPreferences.Editor prefsEditor = myPrefs.edit();
                                System.out.println("Emoji is:- " +arg2);
                                prefsEditor.putInt("key1", arg2);
                                prefsEditor.commit();
                              //  finish();

                dialog.hide();
                        }

                        private SharedPreferences getSharedPreferences(String string,
                                        int modeWorldReadable) {
                                // TODO Auto-generated method stub
                                return null;
                        }
              });

Your SharedPreference Object it's null, and you are treating to access to it.

 private SharedPreferences getSharedPreferences(String string,
                                            int modeWorldReadable) {
                                    return null;
                            }

You need to return something, for example:

private SharedPreferences getSharedPreferences(String string,
                                            int modeWorldReadable) {
                                    return PreferenceManager.getDefaultSharedPreferences(context); //You need to pass an Context object, don't forget it
                            }

I hope that helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜