开发者

Android - How to create a custom (different) spinner

开发者 https://www.devze.com 2023-04-13 07:16 出处:网络
I\'m trying to build and populate a spinner. I have a problem populating it, it gives me the error \"The code for the static initializer is exceeding the 65535 bytes limit\". I need all items I\'ve pu

I'm trying to build and populate a spinner. I have a problem populating it, it gives me the error "The code for the static initializer is exceeding the 65535 bytes limit". I need all items I've put inside spinner. My spinner is set in this way:

public class Names
{
    public static final String ALL_NAMES = "All names";
    public static final String NAMES = "NAMES";
    public static final String OBJECT = "OBJECT";
    private String names;
    private String object;

    public Names(String names, String object){
        super();
        this.names = names;
        this.object开发者_StackOverflow中文版 = object;
    }

    public String getNames() { return names; }
    public String getObject() { return object; }

    public static final Names[] DB = new Names[]{ 
        new Names("Albert","Person"),
        new Names("Bobby","Animal"),...

where the names in second quotes are what I can choose from my spinner and the names in first quotes are the results of my choice. I'd like to make a thing like ExpandableList where I insert a "Parent String" and then all the items for that kind of "Parent String". This is an example:

public class MyExpandableListAdapter extends BaseExpandableListAdapter {
    private String[] groups = { "Persons", "Dogs", "Cats" };
    private String[][] children = {
        { "Albert", "Robert", "Paul" },
        { "Yuri", "Rocky" },
        { "Lisa" },
    };

Is that possible using a custom spinner? I hope you understood what I meant and wrote. Thank you for your help.


I think this is failing because you've used more than 65535 bytes in your static initialiser, or more specifically using a Java source file to enter the..

 public static final Names[] DB = new Names[]{ 
    new Names("Albert","Person"),
    new Names("Bobby","Animal"),...

Will run you into limitations within the compiler / language spec - ie from the JVM spec

"The amount of code per non-native, non-abstract method is limited to 65536 bytes by the sizes of the indices in the exception_table of the Code attribute (§4.7.3), in the LineNumberTable attribute (§4.7.8), and in the LocalVariableTable attribute (§4.7.9). "

This would probably work perfectly well if you stored the data in a database or in a file (which really should be how you're doing this, it's really clunky to be doing it in the java source file) that you load - note that you can run into the 65536 byte limit even if your code takes less than that many bytes, because it's the way it stores it internally that you run into.

You can verify that this is the case if you change your code to read:

 public static final Names[] DB = new Names[]{ 
    new Names("Albert","Person"),
    new Names("Bobby","Animal")};

And run it with that (having deleted the rest of it).

0

精彩评论

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

关注公众号