I am creating a simple application in Android. When I compile and run it in the emulator, it's showing an alert box like this; what it does mean?
sorry, The application simplegame (process com.example.simplegame) has stopped unexpectedly. Please try again!
I'm getting this alert box always? Please explain?
UPDATE:
just trying to import a Picture in it,
import android.app.Activity;
import android.os.Bundle;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
public class SimpleGame extends Activity {
/** Called when the activity is first created. */
private Bitmap mBackGroundImage;
private Canvas canvas;
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mBackGroundImage = hBitmapFactory(R.drawable.background1);
canvas.drawBitmap(mBackGroundImage, 0, 0,null);
setContentView(R.layout.main);
}
private Bitmap hBitmapFactory(int background1)
{
// TODO Auto-generated method stub
return null;
}
}
am newable to android.thats why getting some troubles.
your application is crashing, there must be some exception in your app. Please check the log .
Related
I have a GUI that uploads a bunch of settings via serial once the 'upload' button is pressed.
This upload takes some time and has some Thread.sleep's in it, so during upload the GUI freezes but still allows the user to press the upload button some more, which results in even more freezing.
What would be the best way to directly disable the upload button, upload in the background, and enable the button when finished?
Thanks for the reply.
To answer my own question, I already found a simple solution by creating a task:
public class uploadTask extends Task<String> {
#Override
protected String call() throws Exception {
}
}
I would recommend using RxJavaFx.
import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
import io.reactivex.rxjavafx.observables.JavaFxObservable;
import io.reactivex.rxjavafx.schedulers.JavaFxScheduler;
import io.reactivex.schedulers.Schedulers;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class BackgroundTaskButtonApp extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) throws Exception {
Button button = new Button("Run!");
StackPane stackPane = new StackPane(button);
Scene scene = new Scene(stackPane, 400, 400);
stage.setScene(scene);
stage.show();
JavaFxObservable.actionEventsOf(button)
.doOnNext(event -> button.setDisable(true))
.switchMap(event -> Observable.just(event).observeOn(Schedulers.single()).doOnNext(e -> runLongTask()))
.observeOn(JavaFxScheduler.platform())
.doOnNext(event -> button.setDisable(false))
.subscribe();
}
private void runLongTask() {
System.out.println(Thread.currentThread().getName() + " runLongTask()");
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
I'm writing script to scroll mobile application up and down but Appium studio code with testng framework not working in Eclipse.
I'm new with this kind of script and testing please help to fix it.
I tried Appium studio code.
but it need to fix to run script.
//package <set your test package>;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.TouchAction;
import java.time.Duration;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.testng.annotations.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.logging.Level;
public class scrollandsave {
private String reportDirectory = "reports";
private String reportFormat = "xml";
private String testName = "scrollandsave";
protected AndroidDriver<AndroidElement> driver = null;
DesiredCapabilities dc = new DesiredCapabilities();
#BeforeMethod
public void setUp() throws MalformedURLException {
dc.setCapability("reportDirectory", reportDirectory);
dc.setCapability("reportFormat", reportFormat);
dc.setCapability("testName", testName);
dc.setCapability(MobileCapabilityType.UDID, "330033acecf394bd");
driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), dc);
driver.setLogLevel(Level.INFO);
}
#Test
public void testscrollandsave() {
new TouchAction(driver).press(480, 1348).waitAction(Duration.ofMillis(624)).moveTo(338, 312).release().perform();
new TouchAction(driver).press(591, 1376).waitAction(Duration.ofMillis(592)).moveTo(421, 138).release().perform();
driver.findElement(By.xpath("(//*[#id='listAllImgByCat']/*/*/*/*[#id='icPlayVideo'])[1]")).click();
new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[#text='EDIT']")));
driver.findElement(By.xpath("//*[#text='EDIT']")).click();
new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[#text='SAVE']")));
driver.findElement(By.xpath("//*[#text='SAVE']")).click();
driver.findElement(By.xpath("//*[#text='Export as GIF']")).click();
driver.findElement(By.xpath("//*[#id='btnHome']")).click();
}
#AfterMethod
public void tearDown() {
driver.quit();
}
}
I expect screen should scroll down whenever I execute above code.
you can try this code driver.executeScript("seetest:client.swipe(\"Down\", 1000, 500)");
. This code would swipe from Down, from the offset 1000 for 500ms.
Visit here for more information
I know very little about programming. I downloaded Android Studio and started tinkering with it. I tried to make the app that they put on the tutorial and it worked. However I tried to add more functionality to it and I've failed so far. Excuse me if you see unnecessary junk on my code, I'm just kinda trying everything at first and I do feel a little misguided.
Anyways, onto the question. I have a Switch (id:toggle_text) with an OnClick action (change_font). When the switch is toggled it should change the font size of a different activity through intent1. Currently not only does it not send the font size variable (the variable keeps the default value you put on getIntExtra), but now that I tried to add the ability to save the current state it just shows errors. Here's the code:
package com.example.myfirstapp;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;
import android.widget.TextView;
import static com.example.myfirstapp.R.id.toggle_text;
import static com.example.myfirstapp.R.string.change_font;
public class ShowAnOption extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_an_option);
SharedPreferences sharedPrefs = getSharedPreferences("com.example.xyz", MODE_PRIVATE);
toggle.setChecked(sharedPrefs.getBoolean("NameOfThingToSave", true));
}
public void change_font(View v) {
int fssize;
if (toggle.isChecked())
{
SharedPreferences.Editor editor = getSharedPreferences("com.example.xyz", MODE_PRIVATE).edit();
editor.putBoolean("NameOfThingToSave", true);
editor.commit();
fssize=20;
}
else
{
SharedPreferences.Editor editor = getSharedPreferences("com.example.xyz", MODE_PRIVATE).edit();
editor.putBoolean("NameOfThingToSave", false);
editor.commit();
fssize=40;
}
Intent intent1 = new Intent (getBaseContext(), DisplayMessageActivity.class);
intent1.putExtra("Font_Size", fssize);
}
}
It says "cannot resolve symbol toggle" on toggle.setChecked() and the if statement. What can I do to fix this? Also, why does it not get sent to the other activity? Here's the code on the other activity:
package com.example.myfirstapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TextView;
public class DisplayMessageActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
Intent intent = getIntent();
Intent intent1 = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
int Font_Size = intent1.getIntExtra("Font_Size",50);
TextView textView = new TextView(this);
textView.setTextSize(Font_Size);
textView.setText(message);
ViewGroup layout = (ViewGroup) findViewById(R.id.activity_display_message);
layout.addView(textView);
}
}
Thanks and sorry for the long read. If there's anything else that needs to be known let me know and I'll gladly show.
We did not try to change the font size but here is how to use the switch widget.
Our design is two activities MainActivity and SwitchActivity we changed a CheckBox from unchecked to checked The switch is on the MainActivity code below
setOnCheckedChangeListener();
private void setOnCheckedChangeListener() {
swAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
Toast.makeText(MainActivity.this, "Switch On", Toast.LENGTH_SHORT).show();
Intent intentSP = new Intent(MainActivity.this, SwitchActivity.class );
Bundle extras = new Bundle();
extras.putString("FONT","true" );
intentSP.putExtras(extras);
startActivity( intentSP );
} else {
Toast.makeText(MainActivity.this, "Switch Off", Toast.LENGTH_SHORT).show();
}
}
});
}
Now in the SwitchAcvity we capture the value from the intent and fire the method
doWhat()
Intent intentSP = getIntent();
Bundle bundle = intentSP.getExtras();
tORf = bundle.getString("FONT");
doWhat(null);
And here is the doWhat method
public void doWhat(View view){
if(tORf.equals("true")){
chkBoxOne.setChecked(true);
}else {
Toast.makeText( SwitchActivity.this, "NOT TRUE", Toast.LENGTH_LONG ).show();
}
}
Can anybody help me,
I have been try to test hybrid application (developed in kony ide) using appiumbut the coding not executed .then using UIautomator viewer I didn't get "resource id " so im using by.name method. is der any possibility to get resource id?? then how to make work with hybrid application .
My coding
package com.appium.testcase;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver
public class AppiumTest
{
WebDriver driver=null;
#BeforeClass
public void setup()
{
File appDir = new File("E:/Automation/adt-bundle-windows-x86_64-20130514/sdk");
File app = new File(appDir, "WatsCooking.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "5.1");// motoe
//capabilities.setCapability(CapabilityType.VERSION, "4.2.1");//lava
capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
capabilities.setCapability("app-Package","com.truetech.watcooking");
//Here we mention the activity name, which is invoked initially as app's first page.
capabilities.setCapability("app-Activity","com.truetech.watscooking.SplashActivity");
capabilities.setCapability("deviceName", "ZX1B328HPW");//motoe
//capabilities.setCapability("deviceName", "0123456789ABCDEF");//lava
capabilities.setCapability("app", app.getAbsolutePath());
try {
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
}
#Test
public void loginTest() throws Exception {
try{
System.out.println("call");
List <WebElement> loginbt =driver.findElements(By.id("btnlogin" ));
loginbt.get(1).click();
}
catch(NullPointerException ex1)
{
//System.out.println( "Value not found in Dropdown to Select");
}
}
#AfterMethod
public void tearDown() {
driver.quit();
}
}
You need to expose widget IDs. Do the following:
On the File menu, click Settings. The Project Settings dialog box displays.
Click the Native tab.
On the Common sub-tab, click Expose Widget IDs for Test Automation, and then click Finish.
For the Android platform, when you select to expose widget IDs, an xml file is generated during the build containing the widget IDs of the app. This is explained in detail under Android Limitations.
See the docs for more information.
I have already included the Internet Permissions in the andoird manifest page, still the error seems to persist. I am also recieveing an unknown host excption in the similar code. Kindly guide me through! Ty! :)
package name.id;
import android.app.Activity;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class FirstPage extends Activity implements android.view.View.OnClickListener
{
/** Called when the activity is first created. */
TextView tv;
Button bu;
EditText et;
private static final String SOAP_ACTION="http://lthed.com/GetFullNamefromUserID";
private static final String METHOD_NAME="GetFullNamefromUserID";
private static final String NAMESPACE="http://lthed.com";
private static final String URL="http://vpwdvws09/services/DirectoryService.asmx";
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et=(EditText) findViewById(R.id.editText1);
tv=(TextView) findViewById(R.id.textView2);
bu=(Button) findViewById(R.id.button1);
bu.setOnClickListener((android.view.View.OnClickListener) this);
tv.setText("");
}
public void onClick(View v)
{
// creating the soap request and all its paramaters
SoapObject request= new SoapObject(NAMESPACE, METHOD_NAME);
//request.addProperty("ID","89385815");// hardcoding some random value
//we can also take in a value in a var and pass it there
//set soap envelope,set to dotnet and set output
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet=true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE obj = new HttpTransportSE(URL);
//to make call to server
try
{
obj.call(SOAP_ACTION,soapEnvelope);// in out parameter
SoapPrimitive resultString=(SoapPrimitive)soapEnvelope.getResponse();
//soapObject or soapString
tv.setText("Status : " + resultString);
}
catch(Exception e)
{
tv.setText("Error : " + e.toString());
//e.printStackTrace();
}
}
}
Have you added Internet permission to your manifest:
<uses-permission android:name="android.permission.INTERNET"/>
The error was being thrown because of an error in the URL. The URL needed my IP address to function properly rather than the URL i was providing because that the webservice was not able to understand.
Depending on what KSOAP2 version you are using error may vary.
Its recommend that use KSOAP2 v3+ lib.
Simply use following code to override...
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
and also use...