Cannot Export AIX due to java error

How can I fix this error?
I am developing extension for my app.
The extension I going to make is my own Component to Image

An annotation processor threw an uncaught exception.
[javac] Consult the following stack trace for details.
[javac] java.lang.IllegalArgumentException: Cannot convert Java type 'android.view.View' to Yail type

If possible so just share that part of code where is the error, so we can help you more. Here you’re trying to convert View to Yail type, this is not possible.

I think that the error you’re encountering is because Yail doesn’t recognize ‘android.view.View’ as a compatible type. Yail expects components to be in its own specific format.

@JEWEL is right. Could you check the part of your code where you’re attempting this conversion? It might help to look for a way to convert the View to a Yail type that can represent it, or to modify your approach so that a direct conversion isn’t necessary.

2 Likes
package app.vjdyofficial.designer.imagecreate;

import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Environment;
import android.view.View;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import android.util.Log;

//Added imports

@DesignerComponent(
        version = 2,
        description = "A very interesting Image creator and limiter only for Designer",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "")

@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "android.permission.READ_EXTERNAL_STORAGE, android.permission.WRITE_EXTERNAL_STORAGE, android.permission.READ_MEDIA_IMAGES")

public class ImageCreate {

    //Activity and Context
    private Context context;
    private Activity activity;

    public ImageCreate(ComponentContainer container){
        super(container.$form());
        this.activity = container.$context();
        this.context = container.$context();
    }

    @SimpleFunction(description = "Sample Function Generated by Niotron")
    public void Create(){
        convertViewToImage(view, context);
    }

    @SimpleEvent(description = "Test Event Generated by Niotron")
    public void Success(){
        EventDispatcher.dispatchEvent(this, "TestEvent");
    }

    public static void convertViewToImage(View view, Context context) {
        // Create a bitmap with the same dimensions as the view
        Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);

        // Create a canvas and associate it with the bitmap
        Canvas canvas = new Canvas(bitmap);

        // Draw the view on the canvas
        view.draw(canvas);

        // Save the bitmap to a file
        saveBitmap(bitmap, context);
    }

    private static void saveBitmap(Bitmap bitmap, Context context) {
        // Create a file to save the bitmap
        File directory = new File(Environment.getExternalStorageDirectory(), "YourDirectoryName");
        if (!directory.exists()) {
            directory.mkdirs();
        }

        String fileName = "image.png";
        File file = new File(directory, fileName);

        try {
            // Create a file output stream
            FileOutputStream fos = new FileOutputStream(file);

            // Compress the bitmap and save it to the file
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);

            // Close the file output stream
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

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