Hi,
I have been working on an extension for an AI application, and I have zeroed in on what has been an error I have not been able to resolve, in executing the extension, so I'm hoping I can find some useful help here. Note that for the Java code in the extension, the same lines run successfully in a Java app, so this is a bit confusing.
The error in the extension comes from the execution of "FileInputStream", which I use with only a single string input, which is the path to a .json file. In AI, this file is housed in the basic upload default directory for the project (docs suggests another way which is to pass both a form and filepath string). I know enough to know that all files uploaded are not treated the same, since we know that for images in most blocks, we can usually specify only the file name, while for webviews file paths, for example, we have to distinguish between development or application, etc. I cannot find anything reliable that discusses any differences we should expect for use of this method, so I am hoping some out there may have some ideas. Below is the minimal extension block that throws the error in question(please excuse the imperfect syntax convention at this point). Any information or ideas on how I can resolve this and effectively execute this command, would be great. I also have a simple AI app with the compiled extension included to test, if that is helpful. I do not see an option to share such a thing now, though. Thanks everyone.
Extension Java code:
/////////////////////////////////////////////////////////////////////////
package com.testFileInputStream;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.Form;
import com.google.appinventor.components.runtime.util.*;
import com.google.appinventor.components.runtime.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.io.File;
///
import android.util.Log;
import android.content.Context;
@DesignerComponent(version = testFileInputStream.VERSION,
description = " Testing FileInputStream ",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "")
@SimpleObject(external = true)
public class testFileInputStream extends AndroidNonvisibleComponent implements Component {
public static final int VERSION = 1;
private ComponentContainer container;
private Context context;
private static final String LOG_TAG = "testFileInputStream";
private String filePath;
private String readStatus;
public static final String DEFAULT_EXAMPLE_VAR_VALUE = "default";
public testFileInputStream(ComponentContainer container) {
super(container.$form());
this.container = container;
this.context = container.$context();
}
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING, // change to what type of variable you have
defaultValue = testFileInputStream.DEFAULT_EXAMPLE_VAR_VALUE)
@SimpleProperty(
description = "Test variable")
public void readIt(String inVar) {
this.readStatus = inVar;
}
// Function for testing FileInputStream.
@SimpleFunction(description = "Testing FileInputStream")
public static String testFileInputStream(String filePath) throws IOException, ExecutionException, InterruptedException {
String successRead = "False";
FileIntputStream readData = new FileInputStream(filePath);
successRead = "True";
//...
return successRead;
}
}
//////////////////////////////////////////////////////////////