I am getting an error in line: generateCsvFile("c:\\test.csv");:
I am trying to change my current program's output from a text field to csv file by following this.
I added the imports and then
I added the line generateCsvFile("c:\\test.csv"); to my main, and that is when I got this error... Why so?
Note: I am a beginner
You need to declare and define either a static function using private static void generateCSVFile(String fileName) or a function public void generateCSVFile(String fileName)in some class ABC and call it using ObjectofClassABC.generateCSVFile(string fileName)
See that the line generateCsvFile("c:\test.csv"); is calling a function named generateCsvFile which is not a predefined function, so you will need to make a function named that. And if you see the tutorial, after that line the function generateCsvFile() is defined so unless you define it you cannot call it and that's why it is giving error. Once you add that part your error will go away.
Related
i'm trying to invode aws lambda function using Java in my Eclipse, if i pass input as any string, the function is calling successfully but, i'm seeing null as the output, but i'm expecing the input text itself as output.
Here is my code
package simpledynamodb;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class LambdaFunctionHandler implements RequestHandler<String, String> {
#Override
public String handleRequest(String input, Context context) {
context.getLogger().log("Input is working");
context.getLogger().log("Input: " + input);
// TODO: implement your handler
return null;
}
}
The output looks like
Uploading function code to dynamodbmaven...
Upload success. Function ARN: arn:aws:lambda:us-west-2:169456523019:function:dynamodbmaven
Invoking function...
==================== FUNCTION OUTPUT ====================
null
In my code i'm passing "Hello world" as input text, i'm suppose to see the passed string instead i'm getting null.
My handler class, everything seems to be fine. Here is the pic of my lambda configuration
Can you tell me where i'm wrong in this?.
I'm super late here but the reason you aren't seeing the output is because you are looking at the output in Eclipse - which only returns the result of your function invocation.
You should look at the Cloudwatch Logs for the Lambda to get the logs of the run.
It's printing null because that's what the function is returning.
I assume when you say you should be getting the input text as output, what you really mean is that you should be seeing in the input string in the logs. I'm guessing you have the logging configured such that those logs aren't printing. To get past the logging configuration issues just to see what your input string is, you might try using System.out instead of context.getLogger().log
I wanted to know the best way to process arguments passed to the main method.
User pass the arguments from command line. i.e. I have a shell script which will invoke my java program. I am using this java program to invoke web service.
For Example,The format of the input is as follows
"Ram,ABC,XYZ,null,null,27-04-15" "Raj,EFG,DEF,null,null,25-04-15" "Kiran,IJK,LMN,null,null,20-04-15"
as you see, within each string there are different attribute values(comma separated). and each set of input is space separated. And web service provides two methods which are as follows.
public void processArg(name,addr1,addr2,info1,info2,dob){
}
public void processArg2(name,addr1,addr2){
}
here first method processArg will be used to submit data for each set. Once this method returns success then i need invoke second method processArg2 which will check the status of the submission i.e whether it is success or not.
What is the best way to achieve this? Please let me know if i am not clearly explained.
Thanks
You can use string tokenizer to solve this issue.Following code can solve you problem.
public static void main(String[] args){
for(int i=0;i<args.length;i++){
String dataString=args[i];
String[] splittedData=dataString.trim().split(",");
processArg(splittedData[0],splittedData[1],splittedData[2],splittedData[3],splittedData[4]);
processArg2(splittedData[0],splittedData[1],splittedData[2]);
}
}
How do I call a Java method from Javascript? I tried the following
http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#calling
But it is not working. I can't put the JS into Java file because the library uses a callback. In my App.html file:
function pickerCallback(data) {
var doc = data[google.picker.Response.DOCUMENTS][0];
var name= doc[google.picker.Document.NAME];
var fileId = data.docs[0].id;
// set the path text field
//[instance-expr.]#class-name::field-name
//[instance-expr.]#class-name::method-name(param-signature)(arguments)
// Call static method
//#com.onix.sdm.client.SDM_Mailer::setSelectedFolder(Ljava/lang/String;Ljava/lang/String;)(name, fileId);
$entry(#com.onix.sdm.client.SDM_Mailer::setSelectedFolder(name, fileId));
}
In SDM_Mailer.java:
private static void setSelectedFolder(String folder, String id) {
SDM_Mailer myThis = SDM_Mailer.getInstance();
myThis.textFolder.setText(folder);
myThis.folderId = id;
}
When I load the app, in gives this error in the browser console:
Uncaught SyntaxError: Unexpected token ILLEGAL
On this line:
$entry(#com.onix.sdm.client.SDM_Mailer::setSelectedFolder(name, fileId));
I also tried the line immediately before that (commented for now), which also gave the same error.
I can't put the JS into Java file because the library uses a callback
That's by design - the purpose of this syntax is not to expose methods where they can be called by external JS, but instead to let you call it from within JSNI. This is because the JSNI can be modified to actually call the java method.
If you want to call Java/GWT methods from in plain js, you must expose them for this. You linked http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#calling, but didn't actually use the important part:
public static native void exportStaticMethod() /*-{
$wnd.computeLoanInterest =
$entry(#mypackage.MyUtilityClass::computeLoanInterest(IFI));
}-*/;
This is the important piece - you must expose the function to where the outside JS can call it, but you must do this exposing from within a JSNI func. Note that we are not calling the function here, just referring to it.
I think you missed the Type Parameter:
$entry(#com.onix.sdm.SDM_Mailer::setSelectedFolder(Ljava/lang/String;Ljava/lang/String;)(name, fileId));
JSNI is well explained at DevGuideCodingBasicsJSNI
I have read through the JEditorPane Docs, from what I can understand you simply need to editorpane.setText(String value); however I am quite new to java and this solution does not work with my code. I think I am missing something obvious but completely out of ideas.
I have created a new tab with this class that extends JEditorPane, this class is designed to open the contents of the file, put them on an array, reverse the array (so latest entry is on the top) then display this list in the JEditorPane (using JeditorPane because I need to make the save url's into hyperlinks),
public class HistoryPane extends JEditorPane{
ArrayList<String> historyToSort = new ArrayList<String>();
public HistoryPane(){
setEditable(false);
historySort();
}
public void historySort() {
try (BufferedReader reader = new BufferedReader(new FileReader("BrowserHistory.txt")))
{
String currentLine;
String newLine = new String("\n");
while ((currentLine = reader.readLine()) != null) {
historyToSort.add(currentLine + newLine);
}
} catch (IOException e) {
e.printStackTrace();
}
Collections.reverse(historyToSort);
System.out.println(historyToSort);
}
{
}
private void displayHistory(){
String sorted = historyToSort.toString();
***** HistoryPane.setText(String sorted); <<<------ PROBLEM SYNTAX.*****
}
}
I have tried multiple different entries into the setText() parenthesis with no luck. What am I missing? Thank You.
NOTE:
This class won't compile because it is reliant on another class (I can't paste all of it) but this code sits within a tabbed pane created by my main class:
Error Message:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
Syntax error on token "setText", Identifier expected after this token
Return type for the method is missing
This method requires a body instead of a semicolon
OK, despite the fact that you haven't read the error message, it seems you're really a newbie, so I'll help.
HistoryPane.setText(String sorted);
The above isn't valid Java. A method invocation takes a list of arguments, without a type.
HistoryPane.setText(sorted);
Now that is a valid method invocation. But it tries to invoke a static method called setText() of the class HistoryPane. What you want is to invoke the instance method setText() on the current object. So the valid syntax is
this.setText(sorted);
or simply
setText(sorted);
That should solve this particular compilation error. Don't try to run your app before every compilation error, listed in the Problems view of Eclipse, is fixed.
Note that the above line won't do what you want it to do, but I'll let you investigate what you should do instead.
My advice: don't try using Swing, which is quite a complex beast, if you don't even know how to call a method yet. Start with very simple Java exercises, not involving any GUI, until you're familiar with the Java syntax, and understand how to read, understand and fix basic compilation problems.
http://pastebin.com/m5fa7685e
It seems to fail when getting f3.. Output is:
not ready
File is null
Exception in thread "main" java.lang.NullPointerException
at BuabFile.parseBUAB(BuabFile.java:93)
at AddressBook.createBrowseForm(AddressBook.java:232)
at AddressBook.(AddressBook.java:51)
at Main.main(Main.java:4)"
But not before then - no file not found errors or anything...
My guess would be that the parseBUAB() method receives a "null" argument. Which means that it could be that it is the AddressBook class is responsible for the error.
It looks like you forgot to assign a value to BuabFile.file static field. You may want to add this to the end of your readFile() method:
BuabFile.file = f3;
I am guessing your AddressBook.createBrowseForm method looks something like this:
String filename = ...;
BuabFile buab = new BuabFile(filename);
buab.readFile();
ArrayList<String> buabLines = buab.returnFile(); // Returns null because readFile() never assigned a value to BuabFile.file
ArrayList<Buab> buabList = buab.parseBUAB(buabLines);
From all I can see, you just call parseBUAB(..) with a null value. I can't see the call to that method so you have to check the rest of your code.
For your 'not ready' output, which is created because your BufferedReader f3 is 'not ready', the API says
True if the next read() is guaranteed not to block for input, false otherwise.
Maybe you just call it too fast and the file is not loaded yet. Play with Thread.sleep() before calling ready() on the stream. Maybe a some-milliseconds blocking is just normal for File I/O.
And third - if f3 is the BufferedReader you want to keep, you have to assign it to the member file in the readFile() method. But now that's all I found ;)
I'm confused further but have found an answer sort of - I'm using windows 7 and have tried it on a windows xp computer and the code compiles fine and reads in the file (other errors you lot have noted are to be changed anyway through development - this was just one stick in the way...).
I'm wondering if there is some Windows 7 error with eclipse and opening/reading files...