Error on java indexOf in android [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
in a block of my java code for an android project I'm trying to get position of a character in a string but application closes unexpectedly.
java code :
public void onClickGet(View v){
String getInput = editText.getText().toString();
if(getInput.contains("(") ) {
//inputEx(getInput);
int a = getInput.indexOf("(");
Toast.makeText(getApplicationContext(),a,Toast.LENGTH_LONG).show();
}

Toast only accept string.. convert it to string first
try{
int a = getInput.indexOf("(");
Toast.makeText(getApplicationContext(),a+"",Toast.LENGTH_LONG).show();
}
catch(Exception e){
e.printStackTrace(); // this will show the error is if error caught
}

Related

Java response get doubled on page refresh [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 days ago.
Improve this question
My API response gets doubled every time I refresh my page. Is it because my return object is declared outside and every time I refresh it creates a new entry?
#GetMapping(value = "/getPaymentMethodDetails")
public List<AutoPayAccountBean> executePaymentMethodDetails(HttpServletRequest request) {
executeGetPaymentMethodsForUser(request);
if (Objects.nonNull(getPaymentMethodsList())) {
getPaymentMethodsList().stream().forEach(paymentMethod -> {
AutoPayAccountBean accountBean = new AutoPayAccountBean();
accountBean.setPaymentMethod(paymentMethod.getProfileName());
accountBean.setExpirationDate(expirationDate);
accountBean.setHolder(paymentMethod.getHolder());
accountBean.setStatus(paymentMethod.getStatus());
this.paymentMethodResponse.add(accountBean);
});
}
return paymentMethodResponse;
}

How to insert and display an image in Android? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I want to insert and display an image. But I have some error. Why I have an error at word "with"?
UsersRef.child(currentUserID).addValueEventListener(new ValueEventListener(){
#Override
public void onDataChange(DataSnapshot dataSnapshot){
if(dataSnapshot.exists()){
String image = dataSnapshot.child("Tuition Image").getValue().toString();
Picasso.with(AddAdsActivity.this).load(image).placeholder(R.drawable.camera).into(TuitionImage);
}
}
#Override
public void onCancelled(DatabaseError databaseError){
}
});
Replace this line:
Picasso.with(AddAdsActivity.this).load(image).placeholder(R.drawable.camera).into(TuitionImage);
With this:
Picasso.get().load(image).placeholder(R.drawable.camera).into(TuitionImage);
And that's it.. Your error will be solved.

Assert the URL or Navigate to it appropriately [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have one question - how to write a cucumber hook that asserts the web URL.
Example -
Let's say I am testing - https://www.usatoday.com/tech/
My Given is as follows -
Given I am on the "/tech/" page
I would like a method to add the base url (www.usatoday.com) + "/tech" and assert whether it is currently on that page
(driver.getURL() ==www.usatoday/tech/)
otherwise navigate to that page if I am not there.
Any Java pros that can help me with this? Many thanks my friends.
#Given("^I am on the \"([^\"]*)\" page$")
public void i_am_on_the_page(String arg) throws throwable{
String newBaseURL = getBaseURL() + arg;
String currentURL = driver.getCurrentURL();
try{
Assert.assertEquals(newBaseURL, currentURL);
}
catch(Exception e){
driver.get(newBaseURL);
}
}
I am assuming that you have a function - getBaseURL() that will provide you the base url.

Using IF commands to Check if a button exists in Selenium Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a java selenium program that automatically presses on a button in a website. The code i am using looks like this :
driver.findElement(By.id("button")).click();
I want the program to use if statements if possible.
Thanks for your help.
Use can use findelements by along with if to achieve this. Below code might give you some idea.
if(driver.findElements(by.xpath("//*[#id=253]")).size>0)
{
//element exists with id = 253
// do the stuff
} else
{
//element do not exist with id = 253.
// do the stuff
}
Hope this helps. Thanks.
You may try this:
public void ClickButton () throws InterruptedException
{
WebElement button = driver.findElement(By.id("button"));
String Source = driver.getPageSource();
if (Source.contains(button))
{
button.click();
Thread.sleep(3000);
}
else
{
driver.quit;
}
}
Hope this can be helpful. Let me know if you are still facing problem.

I can get error in this code [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
public class GmailGoogle {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","E:\\ChromeDriver");
WebDriver wd= new ChromeDriver();
wd.manage().window().maximize();
wd.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier");
WebElement signin = wd.findElement(By.xpath("//*[#id="Email"]"));
signin.sendKeys("sakthe");
WebElement next = wd.findElement(By.xpath("//*[#id="next"]"));
next.click();
}
}
Left hand side of an operator must be variable while Running in selenium webDriver..Any one can help me to fix this Error
Just make the double quotes in the xpath to single quotes.
//*[#id="Email"] to //*[#id='Email']
//*[#id="next"] to //*[#id='next']
E:\\ChromeDriver to E:/ChromeDriver.exe
Your scrips works fine after this.

Categories