Error for joining text in extension

The extension is compiled but i get the error

Code:

public Datepicker(ComponentContainer container) {
super(container.$form());
this.container = container;
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
javaMonth = c.get(Calendar.MONTH);
month = javaMonth + 1;
day = c.get(Calendar.DAY_OF_MONTH);
instant = Dates.DateInstant(year, month, day);
}
SimpleFunction(description = "Creates in the arrangement")
public Object CreateArrangement(AndroidViewComponent arrangement / int orientation, boolean scrollable, final boolean clickable /) {
Create(hv2,"Label","title");
title = COMPONENTS.get("title");
//((Label) title).Text("s");
((Label) title).Text(String.join(Dates.MonthName(instant)," ",(String.valueOf(Dates.Year(instant)))));
}

String.join was added to Java in Java 8, and in Android it is available starting at SDK 26 (Android 8.0). If you want to maximize backward compatibility, use TextUtils.join instead.

3 Likes

But why to use any other method when you can easily do it using +.
"String1"+"String2" = "String1String2"

2 Likes

when i change it to
((Label) title).Text((Dates.MonthName(instant))+" "+(String.valueOf(Dates.Year(instant))));

i get error:
Buildfile: /projects/goldv2/appinventor-sources/appinventor/build.xml

extensions:

clean:

init:

common_CommonUtils:

init:

CommonUtils:

common_CommonVersion:

init:

CommonVersion:
[exec] Result: 128
[exec] Result: 128

CopyToRunLibDir:

components_AndroidRuntime:

init:
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/build/components
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/co
components_AndroidRuntime:

init:

CommonConstants:
[javac] Compiling 6 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning

HtmlEntities:
[javac] Compiling 1 source file to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/HtmlEntities
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning

common_CommonVersion:

init:

CommonVersion:
[exec] Result: 128
[exec] Result: 128

AndroidRuntime:
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/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] 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.
[javac] 1 warning
[javac] Creating empty /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/com/google/appinventor/components/runtime/util/package-info.class
[javac] Creating empty /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/com/google/appinventor/components/annotations/androidmanifest/package-info.class
[javac] Creating empty /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/com/google/appinventor/components/runtime/collect/package-info.class
[javac] Creating empty /projects/goldv2/appin [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.
[javac] 1 warning

components_Barcode:

Barcode:

components_ComponentList:

init:

CommonConstants:

ComponentProcessingLib:
[depend] Deleted 6 out of date files in 0 seconds
[javac] Compiling 2 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/ComponentProcessingLib
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[javac] Creating empty /projects/goldv2/appinventor-sources/appinventor/components/build/classes/ComponentProcessingLib/com/google/appinventor/components/annotations/androidmanifest/package-info.class
[javac] Creating empty /projects/goldv2/appinventor-sources/appinventor/components/build/classes/ComponentProcessingLib/com/google/appinventor/components/annotations/package-info.class
[jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/components/build/ComponentProcessingLib.jar

HtmlEntities:

common_CommonUtils:

init:

CommonUtils:

AnnotationProcessors:
[mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AnnotationProcessors
[javac] Compiling 7 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AnnotationProcessors
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: /projects/goldv2/appinventor-sources/appinventor/components/src/com/google/appinventor/components/scripts/ComponentProcessor.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 1 warning
[javac] Creating empty /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AnnotationProcessors/com/google/appinventor/components/scripts/package-info.class
[copy] Copying 22 files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AnnotationProcessors
[jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/components/build/AnnotationProcessors.jar

common_CommonVersion:

init:

CommonVersion:
[exec] Result: 128
[exec] Result: 128

AndroidRuntime:
[javac] Compiling 15 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] 1 warning

Barcode:

ComponentList:
[javac] Compiling 307 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/ComponentList
[javac]
[javac]
[javac] An annotation processor threw an uncaught exception.
[javac] Consult the following stack trace for details.
[javac] java.lang.ClassFormatError: Truncated class file
[javac] at java.lang.ClassLoader.defineClass1(Native Method)
[javac] at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
[javac] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[javac] at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
[javac] at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
[javac] at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
[javac] at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
[javac] at java.security.AccessController.doPrivileged(Native Method)
[javac] at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
[javac] at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
[javac] at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
[javac] at java.lang.ClassLoader.defineClass1(Native Method)
[javac] at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
[javac] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[javac] at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
[javac] at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
[javac] at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
[javac] at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
[javac] at java.security.AccessController.doPrivileged(Native Method)
[javac] at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
[javac] at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
[javac] at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment$NameProcessIterator.hasNext(JavacProcessingEnvironment.java:417)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.hasNext(JavacProcessingEnvironment.java:617)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.atLeastOneProcessor(JavacProcessingEnvironment.java:455)
[javac] at com.sun.tools.javac.main.JavaCompiler.initProcessAnnotations(JavaCompiler.java:1050)
[javac] at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:852)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:523)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:381)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:370)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:361)
[javac] at com.sun.tools.javac.Main.compile(Main.java:56)
[javac] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[javac] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:58)
[javac] at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1160)
[javac] at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:936)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.Target.execute(Target.java:435)
[javac] at org.apache.tools.ant.Target.performTasks(Target.java:456)
[javac] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
[javac] at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
[javac] at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
[javac] at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.Target.execute(Target.java:435)
[javac] at org.apache.tools.ant.Target.performTasks(Target.java:456)
[javac] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
[javac] at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
[javac] at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
[javac] at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.Target.execute(Target.java:435)
[javac] at org.apache.tools.ant.Target.performTasks(Target.java:456)
[javac] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
[javac] at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
[javac] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[javac] at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
[javac] at org.apache.tools.ant.Main.runBuild(Main.java:853)
[javac] at org.apache.tools.ant.Main.startAnt(Main.java:235)
[javac] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
[javac] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:404: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:495: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:306: Compile failed; see the compiler error output for details.

Total time: 13 seconds
(Launcher.java:285)
[javac] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:404: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:495: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:306: Compile failed; see the compiler error output for details.

Total time: 13 seconds

[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:9: error: cannot access ComponentConstants
[javac] import com.google.appinventor.components.common.ComponentConstants;
[javac] ^

when i use textutils.join method i get the error code:

replace = String.valueOf((Integer.valueOf(LAST_ID.replace("cardcal","")))+1);
Create((Arrangement_Logic(weekday)),"Label",(TextUtils.join("labelcal", (replace.toString()))));

why there is "" between both strings? :thinking:

it is a used to add a space @vknow360

Some brackets can be removed:

((Label) title).Text(Dates.MonthName(instant)+" "+Dates.Year(instant).toString()));
1 Like

/projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/sohamtshah2005/Datepicker/Datepicker.java:163: error: int cannot be dereferenced
[javac] ((Label) title).Text(Dates.MonthName(instant)+" "+Dates.Year(instant).toString());

Aren't you using extension template or latest ai sources?
If so then I suggest you to use extension template.

what's that?

2 Likes

Ohk so what do i need to change? And im using applybuilder code editor

The shortest way I can write the code is

((Label) title).Text(Dates.MonthName(instant)+Dates.Year(instant));

And it should work regardless if its the source or extension temple