below is my java file, and i'm exporting the same an separate jar file ,name of the jar is "Softassert"
package com.annuity_payer;
import java.util.Arrays;
import java.util.Map;
import org.testng.Assert;
import org.testng.Reporter;
import com.thoughtworks.selenium.SeleneseTestBase;
public class Softassert extends SeleneseTestBase {
private StringBuffer verificationErrors;
private StringBuffer verificationSuccess;
public Softassert() {
verificationErrors = new StringBuffer();
verificationSuccess = new StringBuffer();
}
public void verifyEquals(String actual, String expected, String msg) {
try {
Assert.assertEquals(actual, expected, msg);
verificationSuccess.append(msg + ":" + " " + "Actual Result:" + " "
+ actual + " " + "Expected Result:" + " " + expected
+ " - Condition PASSED" + "\n");
} catch (AssertionError e) {
verificationErrors.append(e + "-Condition FAILED" + "\n");
}
}
}
so then i'm creating an new project and the jar file is mapped with build path to retrieve an method from the jar file
below are the code
import com.annuity_payer.Softassert.*;
public class testJar {
Softassert prabu = new Softassert();
prabu.verifyEquals("test","test","verification");
from that above i'm creating an object name of "prabu", then try to call desire method (i.e verifyEquals method)
when i try the same its shown an error "syntax error on tokens" Please clarify / help how to call the method from my jar file
You don't need the star in the import if you only want to import "Softassert", use...
import com.annuity_payer.Softassert;
If you want all classes in the annuity_payer package, you can use
import com.annuity_payer.*;
You might be getting confused with "import static" statements
Related
When i try to compile the following code using javac or gradlew
I got the error method does not override or implement a method from a supertype #Override
The error happened to the two #Override functions
How to solve that ?
code.java:
package com.android.commands.locksettings;
import android.os.ResultReceiver;
import android.os.ServiceManager;
import android.os.ShellCallback;
import com.android.internal.os.BaseCommand;
import com.android.internal.widget.ILockSettings;
import java.io.FileDescriptor;
import java.io.PrintStream;
public final class LockSettingsCmd extends BaseCommand {
private static final String USAGE =
"usage: locksettings set-pattern [--old OLD_CREDENTIAL] NEW_PATTERN\n" +
" locksettings set-pin [--old OLD_CREDENTIAL] NEW_PIN\n" +
" locksettings set-password [--old OLD_CREDENTIAL] NEW_PASSWORD\n" +
" locksettings clear [--old OLD_CREDENTIAL]\n" +
"\n" +
"locksettings set-pattern: sets a pattern\n" +
" A pattern is specified by a non-separated list of numbers that index the cell\n" +
" on the pattern in a 1-based manner in left to right and top to bottom order,\n" +
" i.e. the top-left cell is indexed with 1, whereas the bottom-right cell\n" +
" is indexed with 9. Example: 1234\n" +
"\n" +
"locksettings set-pin: sets a PIN\n" +
"\n" +
"locksettings set-password: sets a password\n" +
"\n" +
"locksettings clear: clears the unlock credential\n";
public static void main(String[] args) {
(new LockSettingsCmd()).run(args);
}
#Override
public void onShowUsage(PrintStream out) {
out.println(USAGE);
}
#Override
public void onRun() throws Exception {
ILockSettings lockSettings = ILockSettings.Stub.asInterface(ServiceManager.getService("lock_settings"));
lockSettings.asBinder().shellCommand(FileDescriptor.in, FileDescriptor.out,
FileDescriptor.err, getRawArgs(), new ShellCallback(), new ResultReceiver(null) {});
}
}
Solved by restoring original BaseCommand file, Thanks to #deHaar
I'm trying to access a mule flowVar from within a Java class:
In the mule processor:
flowVars.rootFilePath="c:\test"
From within the mule processor, I'm calling the java method renameFile(oldFile, newFile) :
package com.rename;
import java.io.File;
import org.mule.api.MuleMessage;
public class FileRename {
public String renameFile(String oldFile, String newFile) {
File file1 = new File(message.getInvocationProperty("rootFilePath") + oldFile);
File file2 = new File(message.getInvocationProperty("rootFilePath") + newFile);
file1.renameTo(file2);
return "Renaming " + oldFile + " to: " + newFile;
}
}
However, I'm receiving the error "message cannot be resolved". What am I missing here? Your help is very much appreciated!
Why can't you use onCall Method to do this?
You can use below code as a sample to access message.
public class MyComponent implements Callable {
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
String oldFile = eventContext.getMessage().getProperty('');
return "Renaming " + oldFile + " to: " + newFile;";
}
}
Okay, so I am attempting to make a custom spawners plugin, but I've already hit a bit issue.. I cannot figure out how to change what creature the spawner summons. The code I have currently can be found below (This is a SpawnerSpawnEvent, also everything works other than the spawning of the skeleton, The console gets sent the 'File exists' message, The file does indeed exist (This is done in the block place event, I will also include this below, not sure if it is needed.) so I am very confused on how I could achieve this..) Thank you in advance for your time.
SpawnerSpawnEvent »
package me.askingg.events;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.SpawnerSpawnEvent;
import me.askingg.golems.Main;
public class CreatureSpawn implements Listener {
Main plugin;
#EventHandler
public void coalSpawn(SpawnerSpawnEvent event) {
CreatureSpawner spawner = (CreatureSpawner) event.getSpawner().getBlock().getState();
Location location = spawner.getLocation();
String world = spawner.getWorld().getName().toString();
File locationFile = new File("plugins/Golems/Locations", world + " - " + location.getBlockX() + "-"
+ location.getBlockY() + "-" + location.getBlockZ() + ".yml");
if (locationFile.exists()) {
Bukkit.getConsoleSender().sendMessage(Main.colorCodes(Main.prefix + "&fThe file exists..."));
spawner.setSpawnedType(EntityType.SKELETON);
spawner.update();
}
}
}
BlockPlaceEvent »
package me.askingg.events;
import java.io.File;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import me.askingg.golems.Main;
public class BlockPlace implements Listener {
#EventHandler
public void spawnerPlace(BlockPlaceEvent event) {
Player player = (Player) event.getPlayer();
Block block = event.getBlock();
Location location = block.getLocation();
String world = block.getWorld().getName().toString();
if (block.getType().equals(Material.SPAWNER)) {
if (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName()
.equals(Main.colorCodes("&fSkeleton Spawner"))) {
File locationFile = new File("plugins/Golems/Locations", world + " - " + location.getBlockX() + "-"
+ location.getBlockY() + "-" + location.getBlockZ() + ".yml");
if (!(locationFile.exists())) {
try {
locationFile.createNewFile();
Bukkit.getConsoleSender()
.sendMessage(Main.colorCodes(Main.prefix
+ "&aSuccessfully&f created a new &fSkeleton Spawner&f location &8(&a"
+ world + " &8-&a " + location.getBlockX() + "&8-&a" + location.getBlockY() + "&8-&a"
+ location.getBlockZ() + "&8)"));
} catch (IOException e) {
}
}
}
}
}
}
Alright, so. Based on my quick read of the documentation it looks like you can cast "block" in this instance to CreatureSpawner and then set the spawnType.
Example:
if (block.getType().equals(Material.SPAWNER)) {
CreatureSpawner spawner = (CreatureSpawner) block;
spawner.setSpawnType(EntityType.SKELETON);
}
Be aware some of that maybe pseudo code as I didn't delve that much into the Bukkit API documentation but you should be able to figure it out from there.
I have the following source code:
package com.sample.sonar.report;
import org.sonar.wsclient.Host;
import org.sonar.wsclient.Sonar;
import org.sonar.wsclient.SonarClient;
import org.sonar.wsclient.connectors.HttpClient4Connector;
import org.sonar.wsclient.services.*;
import org.sonar.wsclient.issue.*;
import java.util.List;
public class App {
public static void main(String args[]) {
try {
String url = "http://sample.url.com:9000";
String login = "userid";
String password = "password";
SonarClient client = SonarClient.create(url);
client.builder().login(login);
client.builder().password(password);
IssueQuery query = IssueQuery.create();
query.rules("S1081");
query.languages("c");
IssueClient issueClient = client.issueClient();
System.out.println("About to Run query\n");
Issues issues = issueClient.find(query);
System.out.println("Ran query\n");
List<Issue> issueList = issues.list();
for (int i = 0; i < issueList.size(); i++) {
System.out.println(issueList.get(i).projectKey() + " " +
issueList.get(i).componentKey() + " " +
issueList.get(i).line() + " " +
issueList.get(i).ruleKey() + " " +
issueList.get(i).severity() + " " +
issueList.get(i).message());
}
} catch (Exception ex) {
System.out.println(ex);
}
}
}
Although I can log into Sonar and search the results I am getting the following runtime error
org.sonar.wsclient.base.HttpException: Error 401 on http://sample.url.com:9000/api/issues/search?languages=c&rules=S1081
I believe this is a 401 error which maps to Unauthorized. Am I missing some sort of authentication beyond what I am doing? Thanks in advance.
SonarClient#builder() is a static method which returns a new builder instance each time it is called. So basically, when you write:
SonarClient client = SonarClient.create(url);
client.builder().login(login);
client.builder().password(password);
your are setting the login on one Builder object, setting the password on another and doing nothing from any of them.
The object you are using is the SonarClient create by the method SonarClient#create(String url) which, indeed, has no login nor password, hence the 401 HTTP error.
What you should write is:
SonarClient client = SonarClient.builder()
.url(url)
.login(login)
.password(password)
.build();
I keep getting NullPointerException on this line:
SharedPreferences myPreference = PreferenceManager.getDefaultSharedPreferences(this);
I ran some things through and I believe that I have the wrong context as it is in a subpackage of the main package so I don't think it can reference the XML preference files. I have used this in class's that are in the main package with no trouble but for some reason this causes an exception.
Full code:
package schoolBook.Icestone.Expandable;
import schoolBook.Icestone.Days;
import schoolBook.Icestone.Main;
import schoolBook.Icestone.SetPreference;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public class Lesson1 extends Lessons {
public Lesson1(String name) {
super(name);
// setGroup(" " + Days.getLessonarray(0) + " ");
String key = "W" + Main.getWeek() + "_" + SetPreference.xmlday + "_L"
+ SetPreference.xmllesson + "_Lesson";
System.out.println(key);
try {
SharedPreferences myPreference = PreferenceManager
.getDefaultSharedPreferences(this);
String group = myPreference.getString(key, "def");
setGroup(" " + group + " ");
} catch (NullPointerException ex) {
ex.printStackTrace();
setGroup(" " + Days.getLessonarray(0) + " ");
}
}
}
Lessons class extends Activity so think that may be the source of my problem but im not sure.
File structure:
Icestone
Main.class and some other classes that use shared preference and it works fine
Lessons package (Lesson1 & Lesson are in this package)
XML folder with the preferences in it
if anyone could help shed some light on this problem it would be much appreciated
You can't do this inside the constructor.
If it extends Activity Class it should't has a constructor, you need to handle that inside the oncreate method.