簡體   English   中英

從 Wavemaker 中的 Ecipe 的 import.jar 文件中調用我的 testImage() 方法時出錯

[英]Error Calling my testImage() Method from inside an imported .jar file from Eclipe in Wavemaker

我只是想在 Wavemaker 中調用我的 testImage() 方法。 在Eclipse中完美運行應用程序后,我導入了.jar文件。 但是,當我在 Wavemaker 中的 .jar 文件中調用相同的方法時,它給出了這個錯誤:

  Error
Compile failed with output: [{"filename" : "master/services/MyJavaService1/src/com/demo_jquery/myjavaservice1/MyJavaService1.java","type" : "ERROR","lineNumber" : 134,"columnNumber" : 22,"startPosition" : 4743,"endPosition" : 4751,"message" : "The method testImage() in the type pictures.TestUrl is not applicable for the arguments (java.lang.String)"}]

我現在將向您展示 TestUrl class,我調用它來調用我的兩個方法 testImage() 和 getImage():

package pictures;



import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import javax.imageio.ImageIO;

/*
 * By: Victor Foning
 * 
 * This program will consist of two Methods: 
 * 
 * The First will Test the Validity and reachability of an validity 
 *  of an image URL.
 *  
 * The second methods will log4j
 * 
 * 
 * 
 * 
 * 
 */
public class TestUrl {

       public Boolean testImage (String l) {

         //  String urlString = "http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png";
             System.out.println("Using " + l);

          // Open connection

             URL u = null;
            try {
                u = new URL( l);
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             URLConnection connection = null;
            try {
                connection = u.openConnection();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

          // Check if response code is HTTP_OK (200)

             HttpURLConnection httpConnection 
                   = (HttpURLConnection) connection;
             int code = 0;
            try {
                code = httpConnection.getResponseCode();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             String message = null;
            try {
                message = httpConnection.getResponseMessage();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
             System.out.println(code + " " + message);
             if (code == HttpURLConnection.HTTP_OK) {

                 return true;

             } else {
                return false;
             }



       }

       public void getImage (String u)  {

           BufferedImage image =null;
            try{

                URL url =new URL(u);


                // read the url
               image = ImageIO.read(url);



                ImageIO.write(image, "jpg",new File("C://Users//Foning//Desktop//GeoDataLab//mash7.jpg"));

            }catch(IOException e){
                e.printStackTrace();
            }

        }
}

圖片是在本地下載的,控制台輸出是這樣的:

Using http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png

200 OK 真

這是我的 TestDownload 主要 Class 我通過它調用我的兩個方法:

   package pictures;

import java.io.IOException;


/*
 * By: Victor Foning 17/Septembre/2019
 * 
 * From this Main Methods we will call: 
 * 
 * TestUrl.java and the GetImage.java Methods
 * 
 * 
 * 
 */
public class TestDownload {

    public static void main(String[] args)  {

           String path = "http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png";

        // We Begin encapsulating the TestUrl Methods


        TestUrl im = new TestUrl();

        boolean image = im.testImage(path);
        if(image){
             im.getImage(path);
           System.out.print("true");



        }

        else{
            System.out.print(" victor_WakeUP_false");
        }



    }

}

然后在這里我將.jar 文件(粗體)導出到 Wavemaker 並通過我的 JavaService Class 進行相同的方法調用:

package com.demo_jquery.myjavaservice1;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pictures.TestUrl;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.springframework.beans.factory.annotation.Autowired;


import com.wavemaker.runtime.security.SecurityService;
import com.wavemaker.runtime.service.annotations.ExposeToClient;
import com.wavemaker.runtime.service.annotations.HideFromClient;

在這里,您將找到我在 javaService1 class 中創建的 class getImageFromWaveMaker() 來調用我的兩個方法:

    package com.demo_jquery.myjavaservice1;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pictures.TestUrl;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.springframework.beans.factory.annotation.Autowired;


import com.wavemaker.runtime.security.SecurityService;
import com.wavemaker.runtime.service.annotations.ExposeToClient;
import com.wavemaker.runtime.service.annotations.HideFromClient;

import com.demo_jquery.myjavaservice1.model.*;


@ExposeToClient
public class MyJavaService1 {

    private static final Logger logger = LoggerFactory.getLogger(MyJavaService1.class);

    @Autowired
    private SecurityService securityService;


    public void getImageFromWavemaker( String p) {



           String path  = 
          "http://www.eurobiopark.org/sites/default/files/EurobioparkMashups5.1.png";


        // We Begin encapsulating the TestUrl Methods


        TestUrl im = new TestUrl();

        boolean image = im.testImage(path);
        if(image){
             //im.getImage(url);
           logger.info("true");



        }

        else{
            logger.info("victor_WakeUP_false");
        }

    }
}

請幫我弄清楚為什么我在運行此代碼時會出現錯誤?

感謝一些好朋友的一些冥想和積極的重新定位,我能夠解決這個問題。

我開始意識到,即使在聲明方法時接受了駝峰式。 我在我的 TestUrl Class 中以大寫字母開頭重新聲明了這兩種方法。

參考錯誤代碼:

Aslo, understanding that all classes in java are derived from the object class and that the String class is one of the most important class in Java. 當我在 Z32F72220291696F307EDEZ78 中創建所有類時,我將 java.lang.String class 設為超級 Class。

我做了一個 maven 編譯,它生成了一個.jar 文件。 我繼續在 Wavemaker 上的資源庫文件中上傳 .jar 文件,將我的變量與我的 JavaService class 相應地綁定,結果很好。

請隨時對這個問題發表任何進一步的看法,我很高興聽到它。 謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM