Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exceed 65535 byte limit for method code

Tags:

android

sqlite

I have a product list but Java complains that the method exceeds the limit of 65535 bytes. How can I add more words and overcome the limit?

public class ProductList extends Activity {

   // List view
private ListView lv;

// Listview Adapter
ArrayAdapter<String> adapter;

// Search EditText
EditText inputSearch;

// ArrayList for Listview
ArrayList<HashMap<String, String>> productList;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_product_list);


    String as = System.getProperty("line.separator");

    String products[] = {


            // I want these words to keep in a database
            // Because here is 65kb limit but I need more...



            "Banana"    +as+    "Its color is yellow."  ,
            "Orange"    +as+    "Orange is a sour fruit."   ,
            "Onion" +as+    "Onion usually used on Pizza"   ,
            "Google"    +as+ "Google is a giant search engine." ,
            "Love"  +as+    "Love is related to heart." ,
            "Lily"  +as+    "It  is one kind of white flower."  ,
            "Banana"    +as+    "Its color is yellow."  ,
            "Orange"    +as+    "Orange is a sour fruit."   ,
            "Onion" +as+    "Onion usually used on Pizza"   ,
            "Google"    +as+ "Google is a giant search engine." ,
            "Love"  +as+    "Love is related to heart." ,
            "Lily"  +as+    "It  is one kind of white flower."  ,           
            "Banana"    +as+    "Its color is yellow."  ,
            "Orange"    +as+    "Orange is a sour fruit."   ,
            "Onion" +as+    "Onion usually used on Pizza"   ,
            "Google"    +as+ "Google is a giant search engine." ,







    };



    lv = (ListView) findViewById(R.id.list_view);
    inputSearch = (EditText) findViewById(R.id.inputSearch);

    // Adding items to listview
    adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.p_list,   products);
    lv.setAdapter(adapter);

    /**
     * Enabling Search Filter
     * */
    inputSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text
            ProductList.this.adapter.getFilter().filter(cs);
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
        }
    });


}

}

For easier understanding:

enter image description here

Thanks in advance

like image 665
Jani Avatar asked Dec 12 '12 18:12

Jani


People also ask

How many characters is 65 535 bytes?

A text column can be up to 65,535 bytes. An utf-8 character can be up to 3 bytes. So... your actual limit can be 21,844 characters.


1 Answers

This isn't a limitation to do with Sqlite as far as I can tell - the Eclipse error is showing that it's a problem with the method.

I would strongly suggest that if you have a lot of data, you should keep that in a separate resource. Then just load the resource at execution time. There's no need to have it baked into your code. You can always include some string to replace with the platform line separator if you need to.

like image 78
Jon Skeet Avatar answered Oct 04 '22 23:10

Jon Skeet