I receive the following error:
Error:(7, 22) java: ')' expected when executing my code:
public class Main {
public static void main(String[] args) {
// write your code here
myName( mName:"Gowtham");
}
public static void myName(String mName) {
System.out.println(mName);
}
}
This is the code I wanted to execute but it tells it has errors, learning it through some online courses.
The error is here
myName( mName:"Gowtham");
Just write it as following:
public class Main {
public static void main(String[] args) {
// write your code here
myName("Gowtham");
}
public static void myName(String mName) {
System.out.println(mName);
}
}
Related
I have two java files under the tests directory.
I use the following code to set up Soot for further analysis(i.e., construct a call graph) but meet an error of are the packages set properly?.
Main.java:
public class Main {
static void setupSoot() {
Options.v().set_prepend_classpath(true);
Options.v().set_process_dir(Collections.singletonList("./tests"));
Options.v().set_whole_program(true);
Scene.v().loadNecessaryClasses();
}
// Following function also doesn't work and has a similar error message
//static void setupSoot() {
// Options.v().set_prepend_classpath(true);
// Options.v().set_process_dir(Collections.singletonList("./tests"));
// Scene.v().loadClassAndSupport("FooBar");
//}
public static void main(String[] args) {
setupSoot();
// ....
}
}
And I get the following error message:
Exception in thread "main" java.lang.RuntimeException: Error: couldn't find class: FooBar are the packages set properly?
at soot.JastAddInitialResolver.resolveFromJavaFile(JastAddInitialResolver.java:119)
at soot.JavaClassSource.resolve(JavaClassSource.java:69)
at soot.SootResolver.bringToHierarchyUnchecked(SootResolver.java:253)
at soot.SootResolver.bringToHierarchy(SootResolver.java:221)
at soot.SootResolver.bringToSignatures(SootResolver.java:292)
at soot.SootResolver.bringToBodies(SootResolver.java:332)
at soot.SootResolver.processResolveWorklist(SootResolver.java:171)
at soot.SootResolver.resolveClass(SootResolver.java:141)
at soot.Scene.loadClass(Scene.java:1009)
at soot.Scene.loadClassAndSupport(Scene.java:994)
at soot.Scene.loadNecessaryClasses(Scene.java:1822)
at Main.setupSoot(Main.java:18)
at Main.main(Main.java:21)
If I complie two test files into .class files then I will get following error message:
Exception in thread "main" soot.SootResolver$SootClassNotFoundException: couldn't find class: tests.FooBar (is your soot-class-path set properly?)
at soot.SootResolver.bringToHierarchyUnchecked(SootResolver.java:245)
at soot.SootResolver.bringToHierarchy(SootResolver.java:221)
at soot.SootResolver.bringToSignatures(SootResolver.java:292)
at soot.SootResolver.bringToBodies(SootResolver.java:332)
at soot.SootResolver.processResolveWorklist(SootResolver.java:171)
at soot.SootResolver.resolveClass(SootResolver.java:141)
at soot.Scene.loadClass(Scene.java:1009)
at soot.Scene.loadClassAndSupport(Scene.java:994)
at soot.Scene.loadNecessaryClasses(Scene.java:1822)
at Main.setupSoot(Main.java:18)
at Main.main(Main.java:21)
I beleive that soot prepend_classpath is true since it works well when two test files are not in the package (i.e., remove package tests from both files).
Two files in tests directory are as follows:
Pack.java:
package tests;
public class Pack {
public static void main(String[] args) {
int s = 10;
}
}
FooBar.java
package tests;
public class FooBar {
public static void main(String[] args) {
FooBar callFooBar = new FooBar();
callFooBar.foo(10);
}
void foo(int a) {
bar(a);
}
void bar(int a) {
for (int i = 0; i < a; i++) {
i += a;
}
}
}
I solved this problem. The issue is that the path of the test files is wrong.
Now my project structure is as follows:
-ProjectRoot
|--src
|--Main.java
|--testers
|--easycase
|--FooBar.java
|--Pack.java
and My Main.java:
public class Main {
static void setupSoot() {
Options.v().set_prepend_classpath(true);
// Options.v().set_soot_classpath("xxxxx:xxxxx/xxxxx.jar") // For external packages
Options.v().set_process_dir(Collections.singletonList("./testers"));
Options.v().set_whole_program(true);
Scene.v().loadNecessaryClasses();
}
public static void main(String[] args) {
setupSoot();
Scene.v().loadAndSupport("esaycase.FooBar");
// Do something here
}
}
Note that the first line is package easycase; for both test files.
So why public static void main(String[] args) I got an error. what can i do to resolve it?
package linkedList;
public class HackerRank {
public class Solution {
// Complete the aVeryBigSum function below.
public long aVeryBigSum(long[] ar) {
long a=0;
for(int i=0;i<ar.length;i++){
a=ar[i]+a;
}
return a;
}
public static void main(String[] args) { ///why this line is not correct
Solution s= new Solution();
long[] ar= {10000,20000,30000};
System.out.println(s.aVeryBigSum(ar));
}
}
}
There is another possible solution, taking the nested Solution class out of the HackerRank class, as I see you are not doing anything with it at the moment.
public class Solution {
// Complete the aVeryBigSum function below.
public long aVeryBigSum(long[] ar) {
long a = 0;
for (int i = 0; i < ar.length; i++) {
a = ar[i] + a;
}
return a;
}
public static void main(String[] args) {
Solution s = new Solution();
long[] ar = { 10000, 20000, 30000 };
System.out.println(s.aVeryBigSum(ar));
}
}
This makes sure that your static main method works.
You can't access a static method in a non-static class. There are 2 possible solutions for this problem:
- 1. Make Solution static
public static class Solution {
public static void main(String[] args) {
//...
}
}
- 2. Remove the static from the main method
public class Solution {
public void main(String[] args) {
//...
}
}
I'm writing a program for my class and i'm getting compiling errors and I'm not sure why. I think it has something to do with my Test method.
public class Test1 {
public static void main(String[] args) {
String test;
public void Test(String s){
text = s;
}
Test test = new Test("ABC");
System.out.println(test);
}
}
public class Test1 {
String text;
public Test1(){
}
public Test1(String s){
this.text = s;
}
public static void main(String[] args) {
Test1 test = new Test1("ABC");
System.out.println(test.text);
}
}
Try this..
This is my code.
I get an error saying:
variable ana of type Analyse
cannot find symbol: ana.lesUlovligeOrd
cannot find symbol: ana.sensurerTekst
Why?
import easyIO.*;
import java.util.*;
public class Eksamen {
public static void main (String[] args) {
Analyse ana = new Analyse();
ana.lesUlovligeOrd("sensurord.txt");
ana.sensurerTekst("roman.txt", "sensurert-roman.txt");
}
}
class Analyse {
In tast = new In();
Out skjerm = new Out();
void lesUloveligeOrd(String s){
}
void sensurerTekst(String s, String t){
}
}
you called ana.lesUlovligeOrd("sensurord.txt");
but actually void lesUloveligeOrd(String s) in Analyse class.
so you call like this ana.lesUloveligeOrd("sensurord.txt");
my code, being practically identical to the code given in BlackBerry's tutorial, has a syntax error in Eclipse. i'm sure there is some small but i'm just not seeing, but my coworker could not find it as well. any ideas would be greatly appreciated. thanks!
Code:
pushScreen(new ABCScreen());
Error:
Cannot make a static reference to the
non-static method pushScreen(Screen)
from the type UiApplication
here is the complete source:
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class AwesomeBBCalculator extends UiApplication {
public AwesomeBBCalculator() {
AwesomeBBCalculator app = new AwesomeBBCalculator();
app.enterEventDispatcher();
}
public static void main(String[] args) {
pushScreen(new ABCScreen()); // ERROR LINE
}
}
final class ABCScreen extends MainScreen {
public ABCScreen() {
super();
// add title
LabelField title = new LabelField("Awesome BlackBerry Calculator",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
}
public boolean onClose() {
Dialog.alert("Thanks for using the Awesome BlackBerry Calculator!\nGoodbye.");
System.exit(0);
return true;
}
}
The pushScreen method can only be called within an instance of UiApplication. You are trying to call it from a static main method. That does not work. Do this instead...
public void foo()
{
pushScreen(this);
}
public static void main(String[] args)
{
(new ABCScreen()).foo();
}
public void class1()
{
pushScreen(this);
}
public static void main(String[] args)
{
(new NewScreen()).class1();
}
try making an object for the ABCScreen class and then use it or u may try this also:
UiApplication.getUiApplication().pushScreen(new ABCScreen());