gpt4 book ai didi

java - 从 Wavemaker 中的 Eclipse 导入的 .jar 文件中调用我的 testImage() 方法时出错

转载 作者:太空宇宙 更新时间:2023-11-04 09:22:15 27 4
gpt4 key购买 nike

我只是想在 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 类,我调用该类来调用我的两个方法 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 好正确

这是我的 TestDownload 主类,我通过它调用我的两个方法:

   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 类进行相同的方法调用:

包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 类中创建的类 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");
}

}
}

请帮我弄清楚为什么我运行此代码时会出现错误?

最佳答案

多亏了一些好 friend 的一些冥想和积极的重新定位,我才能够解决这个问题。

我开始意识到,即使在声明方法时接受驼峰命名法。我在 TestUrl 类中重新声明了这两种方法,并以大写字母开头。

引用错误代码:

Aslo,了解java中的所有类都是从对象类派生的,并且String类是Java中最重要的类之一。当我在 Eclipse 中创建所有类时,我将 java.lang.String 类设置为 super 类。

我做了一个maven编译,它生成了一个.jar文件。我继续将 .jar 文件上传到 Wavemaker 上的资源库文件中,将我的变量与我的 JavaService 类相应绑定(bind),结果很好。

请随意表达对此问题的任何进一步看法,我很高兴听到。谢谢你!

关于java - 从 Wavemaker 中的 Eclipse 导入的 .jar 文件中调用我的 testImage() 方法时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58168433/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com