Android 我需要扩展一个类型为plugin和Activity的类,但出现错误:myclass类型的方法mymethod()未定义

Android 我需要扩展一个类型为plugin和Activity的类,但出现错误:myclass类型的方法mymethod()未定义,android,phonegap-plugins,Android,Phonegap Plugins,我是Java新手,我正在尝试使用phonegap在android设备上测试这个插件 问题是,我的android插件必须从插件扩展而来,但用于创建文件的其他一些代码(openFileOutput,getFileStreamPath)需要位于扩展到活动的类中 所以,通过大量阅读,我发现我不能从超过1个类扩展,但我可以创建内部类,所以我创建了一个名为:SiberiaPrint的内部类,它从活动扩展而来 问题是,当我调用performTest方法时,我得到了错误1:对于SibPrintV2类型,perf

我是Java新手,我正在尝试使用phonegap在android设备上测试这个插件

问题是,我的android插件必须从插件扩展而来,但用于创建文件的其他一些代码(openFileOutput,getFileStreamPath)需要位于扩展到活动的类中

所以,通过大量阅读,我发现我不能从超过1个类扩展,但我可以创建内部类,所以我创建了一个名为:SiberiaPrint的内部类,它从活动扩展而来

问题是,当我调用performTest方法时,我得到了错误1:对于SibPrintV2类型,performTest()方法未定义

在方法声明中,我得到一个错误:方法的返回类型丢失。

我已尝试使用public void SibPrintV2.this.performTest(),但不起作用

我被困在这里,任何帮助都将不胜感激。 谢谢

--这是密码--

导入java.io.File;
导入java.io.FileOutputStream;
导入java.io.IOException;
导入android.content.Context;
导入android.os.Bundle;
导入android.os.Looper;
导入com.zebra.sdk.comm.BluetoothConnection;
导入com.zebra.sdk.comm.Connection;
导入com.zebra.sdk.comm.ConnectionException;
导入com.zebra.sdk.printer.PrinterLanguage;
导入com.zebra.sdk.printer.ZebraPrinter;
导入com.zebra.sdk.printer.ZebraPrinterFactory;
导入com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;
导入com.stihn.sibmovil.util.SettingsHelper;
导入com.stihn.sibmovil.util.UIHelper;
导入org.apache.cordova.api.Plugin;
导入org.apache.cordova.api.PluginResult;
导入org.json.JSONArray;
导入org.json.JSONException;
导入android.app.Activity;
导入android.app.ProgressDialog;
公共类SibPrintV2扩展插件{
公共静态字符串macAddress;
公共PluginResult执行(字符串操作、JSONArray参数、字符串回调ID){
试一试{
if(action.equals(“sibPrintTicket”)){
字符串echo=args.getString(0);
最终字符串filepath=args.getString(1);
macAddress=args.getString(2);
if(echo!=null&&echo.length()>0){

performTest();//“我确实创建了一个名为:siberia print的内部类,它从Activity扩展而来。”:不要这样做。
活动
是一个特例类,而不仅仅是一个通用Java类。我对phonegap或其插件一无所知,但如果有什么需要的话,它应该是
活动
的一个内部类,而不是相反。谢谢你的评论。你知道如何在同一个类上扩展活动和插件吗?在Java中,您不能从多个类进行扩展。如果可以从phonegap插件启动Android活动,我建议您这样做。您可以将数据作为用于启动活动的意向“额外”传递,也可以将其保存在单独的Java类中。我看到这里关于堆栈溢出的问题中提到的phonegap/Android非常常见所以我肯定你不是第一个做你想做的事情的人。我建议在这里搜索或者谷歌搜索。
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import android.content.Context;
import android.os.Bundle;
import android.os.Looper;

import com.zebra.sdk.comm.BluetoothConnection;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.printer.PrinterLanguage;
import com.zebra.sdk.printer.ZebraPrinter;
import com.zebra.sdk.printer.ZebraPrinterFactory;
import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;
import com.stihn.sibmovil.util.SettingsHelper;
import com.stihn.sibmovil.util.UIHelper;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.app.ProgressDialog;

public class SibPrintV2 extends Plugin{

        public static String macAddress;

        public PluginResult execute(String action, JSONArray args, String callbackId) {
            try {
                if (action.equals("sibPrintTicket")) {
                    String echo = args.getString(0);
                    final String filepath = args.getString(1);
                    macAddress = args.getString(2);
                    if (echo != null && echo.length() > 0) {
                        performTest();   // <<<<*********** Error 1: The method performTest() is undefined for the type SibPrintV2 ************
                        return new PluginResult(PluginResult.Status.OK, "Printing..");
                    } else {
                        return new PluginResult(PluginResult.Status.ERROR);
                    }
                } else {
                    return new PluginResult(PluginResult.Status.INVALID_ACTION);
                }
            } catch (JSONException e) {
                return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
            }
        }


    private class SiberiaPrint extends Activity{

    private UIHelper helper = new UIHelper(this);

    public void SibPrintV2.performTest() { // <<<<*********** Error 2: Return type for the method is missing.  
                                                                //Multiple markers at this line
                                                                  //- void is an invalid type for the variable SibPrintV2
                                                                  //- Return type for the method is missing
                                                                  // - Syntax error on token ".", ; expected **************
        new Thread(new Runnable() {
            public void run() {
                Looper.prepare();
                sendFile();
                Looper.loop();
                Looper.myLooper().quit();
            }
        }).start();

    }

    private void sendFile() {
        Connection connection = null;
            connection = new BluetoothConnection(SibPrintV2.macAddress);
        try {
            helper.showLoadingDialog("Sending file to printer ...");
            connection.open();
            ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);
            testSendFile(printer);
            connection.close();
        } catch (ConnectionException e) {
            helper.showErrorDialogOnGuiThread(e.getMessage());
        } catch (ZebraPrinterLanguageUnknownException e) {
            helper.showErrorDialogOnGuiThread(e.getMessage());
        } finally {
            helper.dismissLoadingDialog();
        }
    }

    private void testSendFile(ZebraPrinter printer) {
        try {
            File filepath = getFileStreamPath("TEST.LBL");
            createDemoFile(printer, "TEST.LBL");
            printer.sendFileContents(filepath.getAbsolutePath());
            SettingsHelper.saveBluetoothAddress(this, SibPrintV2.macAddress);

        } catch (ConnectionException e1) {
            helper.showErrorDialogOnGuiThread("Error sending file to printer");
        } catch (IOException e) {
            helper.showErrorDialogOnGuiThread("Error creating file");
        }
    }

    private void createDemoFile(ZebraPrinter printer, String fileName) throws IOException {

        FileOutputStream os = this.openFileOutput(fileName, Context.MODE_PRIVATE);

        byte[] configLabel = null;

        PrinterLanguage pl = printer.getPrinterControlLanguage();
        if (pl == PrinterLanguage.ZPL) {
            configLabel = "^XA^FO17,16^GB379,371,8^FS^FT65,255^A0N,135,134^FDTEST^FS^XZ".getBytes();
        } else if (pl == PrinterLanguage.CPCL) {
            String cpclConfigLabel = "! 0 200 200 406 1\r\n" + "ON-FEED IGNORE\r\n" + "BOX 20 20 380 380 8\r\n" + "T 0 6 137 177 TEST\r\n" + "PRINT\r\n";
            configLabel = cpclConfigLabel.getBytes();
        }
        os.write(configLabel);
        os.flush();
        os.close();
    }
  }
}