Query about lists in extension

i want to create lists and im using the push method to add items but it shows me an error

private String[] cardviews;
private String[] label_components;
cardviews.push(LAST_ID);
label_components.push(LAST_ID);

Error:
[javac] symbol: variable CornerRadius
[javac] location: class Datepicker
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:204: error: cannot find symbol
[javac] cardviews.push(LAST_ID);
[javac] ^
[javac] symbol: method push(String)
[javac] location: variable cardviews of type String[]
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:218: error: cannot find symbol
[javac] label_components.push(LAST_ID);
[javac] ^
[javac] symbol: method push(String)
[javac] location: variable label_components of type String[]
[javac] Note: Some input files use or override a deprecated API.

If you know the basics of JAVA, you'll know you can't add items to an array.
The push method is not for array.

If you want to add item (when you don't know how many elements will be), use java.util.List.
There is a method called add.

Example:

import java.util.*;
.
.
.
List<String> list  = new ArrayList<>();
list.add("Hello World!");
// The list will contain one element "Hello World"
3 Likes

and how do i again set it to an empty list again in a void?

Two solutions:
1- set it to null:
myArray = null;
2- reset it again to an empty array:

myArray = new ArrayList<>();

3- clear method:
https://developer.android.com/reference/java/util/ArrayList#clear()

1 Like

i already tried this but get error

I also tried this but i got error
list.clear();

and also errors for adding items and selecting items

AndroidRuntime:
[javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:177: error: cannot find symbol
[javac] firstrow.clear();
[javac] ^
[javac] symbol: method clear()
[javac] location: variable firstrow of type String
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:178: error: cannot find symbol
[javac] lastrow.clear();
[javac] ^
[javac] symbol: method clear()
[javac] location: variable lastrow of type String
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:202: error: cannot find symbol
[javac] firstrow.add(i);
[javac] ^
[javac] symbol: method add(int)
[javac] location: variable firstrow of type String
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:204: error: cannot find symbol
[javac] for (int i = 0; i<=firstrow.length();i++)
[javac] ^
[javac] symbol: method length()
[javac] location: variable firstrow of type String
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:206: error: cannot find symbol
[javac] dynamic(firstrow.select(i),-6381922,(addmonth - 1));
[javac] ^
[javac] symbol: method select(int)
[javac] location: variable firstrow of type String
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.

because you are not using ArrayList type .You are using String[] type.So all of the above posts won't work for you.

1 Like
  [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:81: error: unexpected type
[javac]     private List<int>  firstrow = new ArrayList<>(); 
[javac]                  ^
[javac]   required: reference
[javac]   found:    int
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:82: error: unexpected type
[javac]     private List<int>  lastrow = new ArrayList<>(); 
[javac]                  ^
[javac]   required: reference

i want the lastrow and firstrow variable to store int values in the list

Hi
You cannot use primitive types (like int) as a generic parameter. Use the boxed equivalent (Integer) instead

2 Likes

yes thank you it worked but select item is not working

[javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:206: error: cannot find symbol
[javac] dynamic(firstrow.select(i),-6381922,(addmonth - 1));
[javac] ^
[javac] symbol: method select(int)
[javac] location: variable firstrow

There isn't a method called select(int) in the class ArrayList. Use get(int) instead.Also you can read here the Android Documentation for the ArrayList, so you know what is the right method names you should use:
https://developer.android.com/reference/java/util/ArrayList

1 Like

Thank you it worked

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.