0

I am currently working on my android application and sadly, I came at a dead end. I am using the sample from Bitmapfun . My problem is this : The sample is working fine but I have tried every single way trying to populate the two arrays that are included in the Images class and provide the images to the grid. So every time I pass different parameters, different images will be added into the two arrays and get displayed into the grid.

DatabaseHandler.java

public String[] getImagesUrl(String rest_name, String area) {
    String[] images_url = new String[] {};

     // Select All Query
       String selectQuery = "SELECT * FROM menu_images where _area ='" + area + "'" + " AND rest_name='" + rest_name + "'";


       SQLiteDatabase db = this.getReadableDatabase();
       Cursor cursor = db.rawQuery(selectQuery, null); 

    // looping through all rows and adding to list
       if (cursor.moveToFirst()) {
           for (int i = 0; i < cursor.getCount(); i++)
            {
                images_url[i] = cursor.getString(cursor.getColumnIndex("_images"));
                cursor.moveToNext();
            }  
       }

       // closing connection
        cursor.close();
        db.close();

       return images_url;
}

Images.java

import java.util.ArrayList;
import java.util.List;

import com.example.project.DatabaseHandler;

public class Images {

private static DatabaseHandler dbHandler;

public final static String[] imageUrls = new String[] {
    "http://xtcgamers.com/images/pic2.png",
};


public final static String[] imageThumbUrls = new String[] {
    "http://xtcgamers.com/thumb_images/pic2.png",
};
}

How should I call my other method so I can populate those two Arrays? Because when I am trying to, I always get some kind of exception (it depends if I try to convert arraylists to arrays and back, etc.)

Any kind of help is appreciated. I've been stuck for over a week.

Thanks in advance, harris

ps. I do NOT want to use an arraylist here, I really need to use a simple array .

edit: I have tested out some dummy data and tried to call my DatabaseHandler method from another activity and it's working fine. So I guess the problem is somewhere else.

Here is my logcat :

12-14 21:23:25.753: E/AndroidRuntime(9899): FATAL EXCEPTION: main 12-14 21:23:25.753: E/AndroidRuntime(9899): java.lang.ExceptionInInitializerError 12-14 21:23:25.753: E/AndroidRuntime(9899): at com.example.project.ui.ImageGridFragment$ImageAdapter.getCount(ImageGridFragment.java:221) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.widget.GridView.setAdapter(GridView.java:131) 12-14 21:23:25.753: E/AndroidRuntime(9899): at com.example.project.ui.ImageGridFragment.onCreateView(ImageGridFragment.java:97) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:871) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:523) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.app.Activity.performStart(Activity.java:3791) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1620) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.os.Handler.dispatchMessage(Handler.java:99) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.os.Looper.loop(Looper.java:123) 12-14 21:23:25.753: E/AndroidRuntime(9899): at android.app.ActivityThread.main(ActivityThread.java:3683) 12-14 21:23:25.753: E/AndroidRuntime(9899): at java.lang.reflect.Method.invokeNative(Native Method) 12-14 21:23:25.753: E/AndroidRuntime(9899): at java.lang.reflect.Method.invoke(Method.java:507) 12-14 21:23:25.753: E/AndroidRuntime(9899): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 12-14 21:23:25.753: E/AndroidRuntime(9899): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 12-14 21:23:25.753: E/AndroidRuntime(9899): at dalvik.system.NativeStart.main(Native Method) 12-14 21:23:25.753: E/AndroidRuntime(9899): Caused by: java.lang.NullPointerException 12-14 21:23:25.753: E/AndroidRuntime(9899): at com.example.project.provider.Images.(Images.java:61) 12-14 21:23:25.753: E/AndroidRuntime(9899): ... 22 more

7
  • what exception you are getting ? Commented Dec 14, 2012 at 15:20
  • I usually get : 12-14 15:29:26.223: E/AndroidRuntime(584): java.lang.ExceptionInInitializerError 12-14 15:29:26.223: E/AndroidRuntime(584): at com.example.project.ui.ImageGridFragment$ImageAdapter.getCount(ImageGridFragment.java:221), but maybe I am just not calling my method right. I don't know really. Commented Dec 14, 2012 at 15:24
  • you haven't provided getCount() method here Commented Dec 14, 2012 at 15:26
  • What do you mean by that? What should I use instead? Commented Dec 14, 2012 at 15:39
  • I mean to say where is method com.example.project.ui.ImageGridFragment$ImageAdapter.getCount(ImageGridFragment‌​.java:221) ... Commented Dec 14, 2012 at 15:41

1 Answer 1

0

If your trying to implement BitmapFun sample, I suggest you ditch that whole array of urls, and change library's loadImage method, to take String url directly (just comment out the one that takes int and imageView), and use the imageFetcher.loadImage(item.imageUrl, imageView) directly in your adapter's getView

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.