Android AdMob crashes app on start - crash

I don't what's wrong with this code but AdMob crashes the App. I made a new project with just AdMob in it and it still crashes. Any ideas?
I imported the AdMob .jar rightclick project > Properties > Java Build Path > add external JARs and added the GoogleAdMobAdsSdk...jar
layout xml:
<LinearLayout xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="12345678901234567890"
ads:adSize="BANNER"
ads:loadAdOnCreate="true" />
</LinearLayout>
main java:
package com.example.admob;
import android.app.Activity;
import android.os.Bundle;
import com.google.ads.AdRequest;
import com.google.ads.AdView;
public class MainActivity extends Activity {
AdView adView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdRequest adR = new AdRequest();
adR.addTestDevice("4df1559f64826fed");
adView = (AdView)findViewById(R.id.linearLayout);
adView.loadAd(adR);
}
#Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
Please help :)

Your problem is:
adView = (AdView)findViewById(R.id.linearLayout);
Instead you want:
adView = (AdView)findViewById(R.id.adView);
to find the AdView instead of the LinearLayout. You're app is crashing because you're trying to cast a LinearLayout to an AdView.
I recommend you view the LogCat output from Android so you can see why it's complaining. It'll be a useful tool as you start working with Android. You can add it into Eclipse via:
Window -> Show View -> Other... -> Android/Logcat

Related

Cucumber not finding default step definition class

My cucumber runner class cannot seem to find my step definition class, but it finds the feature file just fine.
Here is a snapshot of my very simple project structure:
Feature file:
Feature: Customer must be able to reach the Home Delivery page by clicking the Home Delivery button
Scenario: Test Home Delivery button
Given PS Restaurants web page is open
When User clicks on Home Delivery button
Then Home Delivery page should load
Step Definition class:
package stepDefinitions;
import java.util.concurrent.TimeUnit;
public class E_1_US_1 {
#Given("^PS Restaurants web page is open$")
public void ps_Restaurants_web_page_is_open() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#When("^User clicks on Home Delivery button$")
public void user_clicks_on_Home_Delivery_button() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#Then("^Home Delivery page should load$")
public void home_Delivery_page_should_load() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
}
Runner class:
package runner;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(
features= {"src/features/Feature_1_1.feature"},
glue= {"src/stepDefinitions/E_1_US_1.java"}
)
public class Runner {
}
The output from running the Runner class as a JUnit test:
1 Scenarios ([33m1 undefined[0m)
3 Steps ([33m3 undefined[0m)
0m0.040s
You can implement missing steps with the snippets below:
#Given("^PS Restaurants web page is open$")
public void ps_Restaurants_web_page_is_open() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#When("^User clicks on Home Delivery button$")
public void user_clicks_on_Home_Delivery_button() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#Then("^Home Delivery page should load$")
public void home_Delivery_page_should_load() throws Exception {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
I just copied and pasted the output into my step definitions class and it still won't recognize the step definitions class. Earlier it was saying that there was no matching glue code for each step in the scenario, but that went away after I closed and reopened the feature file.
You can update your runner class as below:
package runner;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(
features= {"src/features"}, //It will pick all the feature files located in this folder
glue= {"stepDefinitions"} //Only package name is required here.
)
public class Runner {
}

unable to run my JavaFX project on IntelliJ IDEA with JDK-11

I am doing a project in IntelliJ IDEA on JavaFX application for the first time. I am unable to run my code.
When I first build->Run, I got an error saying that I require kotlin stdlib in my module,then I downloaded and added kotlin standard library into my module.
But now I am getting java.lang.NoClassDefFoundError in my code .
Sample.Main
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
module-info.java file
module Calculator {
requires javafx.fxml;
requires javafx.controls;
requires kotlin.stdlib;
opens Sample;
}
fxml file
<GridPane fx:controller="Sample.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>
error message:
"C:\Program Files\Java\jdk-11.0.1\bin\java.exe" "-javaagent:C:\Coding_Setups\JetBrains\IntelliJ IDEA Community Edition 2019.1.2\lib\idea_rt.jar=52562:C:\Coding_Setups\JetBrains\IntelliJ IDEA Community Edition 2019.1.2\bin" -Dfile.encoding=UTF-8 -classpath "G:\JavaFXproject\Calculator\out\production\Calculator;C:\Coding_Setups\javafx lib\javafx-sdk-11.0.2\lib\javafx.swing.jar;C:\Coding_Setups\javafx lib\javafx-sdk-11.0.2\lib\javafx.web.jar;C:\Coding_Setups\javafx lib\javafx-sdk-11.0.2\lib\javafx.media.jar;C:\Coding_Setups\javafx lib\javafx-sdk-11.0.2\lib\javafx.graphics.jar;C:\Coding_Setups\javafx lib\javafx-sdk-11.0.2\lib\javafx.fxml.jar;C:\Coding_Setups\javafx lib\javafx-sdk-11.0.2\lib\javafx.controls.jar;C:\Coding_Setups\javafx lib\javafx-sdk-11.0.2\lib\javafx.base.jar;C:\Coding_Setups\javafx lib\javafx-sdk-11.0.2\lib\javafx-swt.jar" sample.Main
Error: Could not find or load main class sample.Main
Caused by: java.lang.NoClassDefFoundError: Sample/Main (wrong name: sample/Main)
I am confused why would my javafx project demand for kotlin stdlib and why I have added it to my module I am getting a new error even when I have not changed the provided code yet.

Launch Eclipse Product File Programmatically?

I want to write an Eclipse plugin that lists all product files within a workspace and is able to launch them. Is there a way to launch an eclipse .product file programmatically?
On the file within the Eclipse ide there is a launch button. The file can be launched as well by right clicking and select: "Run as Eclipse Application."
look at -application flag to eclipse command line
see here : https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html
note you need to set the launcher that is platform specific too
The code can be found inside org.eclipse.pde.ui.launcher.EclipseLaunchShortcut
I use the code this way:
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.internal.core.iproduct.IProduct;
import org.eclipse.pde.internal.core.iproduct.IProductModel;
import org.eclipse.pde.internal.core.product.WorkspaceProductModel;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.launcher.LaunchAction;
#SuppressWarnings("restriction")
public class LaunchExecutor {
private void launchProduct(IFile productFile) {
String mode = "debug";
IProductModel workspaceProductModel = new WorkspaceProductModel(productFile, false);
try {
workspaceProductModel.load();
} catch (CoreException e) {
PDEPlugin.log(e);
}
IProduct product = workspaceProductModel.getProduct();
new LaunchAction(product, productFile.getFullPath().toOSString(), mode).run();
}
}

Android Instrumentation Tests Stuck "Running Tests" Forever Android Studio

I use Android Espresso Tests with latest Android Studio 2.1.2 and Tests are running ok but it does not seems like the standalone test app returns back the results to reflect back to Android Studio and it shows Running Tests Forever
I realize this is an old question, but I just ran into this and didn't see any other search results that had the same problem.
In my case, this was caused by the code under test having a stack overflow exception, which it seems that the test runner failed to handle. I was only able to figure it out by looking at the "Android Monitor" and looking in the logcat.
So if you get to the point where AS just sits at "running test" forever, you might want to look in logcat for an exception that the test runner couldn't handle.
You have to try removing testCoverageEnabled option from build.gradle file if it's there.
possible duplicate
Gradle build tool long for android Tests
In case this helps anyone.
In my case, I was setting the idle state wrongly(false instead of true) after doing a background task, so espresso was stuck thinking that was idle.
You can add an exit test class like this and include this in your Test Suite or Executor in the last
import android.os.Looper;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
import org.junit.FixMethodOrder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import java.io.IOException;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
#RunWith(AndroidJUnit4.class)
#FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ExitTests {
#Rule
public ActivityTestRule<MainActivity> myActivityTestRule =
new ActivityTestRule<>(MainActivity.class, false, true);
public void init(){
getInstrumentation().waitForIdleSync();
if(Looper.myLooper() == null)
Looper.prepare();
}
#Test
public void Exit() throws InterruptedException, IOException {
Runtime.getRuntime().exec(new String[] {"am", "force-stop", "com.package.name"});
}
}
Here is the Test Suite
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
#RunWith(Suite.class)
#Suite.SuiteClasses({ABC.class, ExitTests.class})
public class TestExecutionOrder {
}

Robotium BDD with Cucumber

I want to know if you guys know how to make BDD tests with Robotium.
As I research Robotium works with a different Virtual Machine (Dalvik) so I cannot run as Junit Test (Only with Android Junit Test). So I found a possible solution to run Robotium with Junit with RoboRemote https://github.com/groupon/robo-remote. But when i tried to integrate with cucumber the tests became unstable.
So you guys know some way to make BDD tests using Robotium?
I have successfully integrated Robotium using Cucumber-JVM for Android.
For information about the now official cucumber-android module for Cucumber-JVM and the installation, have a look here. You can also find API-documentation and examples about Cucumber-JVM here: http://cukes.info/platforms.html.
In your test-module for your app, simply add the Robotium Solo jar-file as a dependency (Scope: Compile).
One of my test-classes looks like this:
public class CucumberSteps extends ActivityInstrumentationTestCase2<YourActivity> {
private Solo solo;
public CucumberSteps() {
super(YourActivity.class);
}
#Override
protected void setUp() throws Exception {
super.setUp();
}
#Before
public void before() {
solo = new Solo(getInstrumentation(), getActivity());
}
#After
public void after() throws Throwable {
//clean up
solo.finalize();
}
#Override
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
super.tearDown();
}
#Given("^step_given_description$")
public void step_given_description() throws Throwable {
final View testView = solo.getView(R.id.testView);
solo.waitForView(testView);
solo.clickOnView(testView);
// and so on
}
}
I hope this is enough information for anyone to get started. When this question was asked, cucumber-android didn't exist yet. Keep in mind though, GUI tests are very often somewhat unstable! I managed to get a stable set of tests locally, but e.g. in Jenkins, usually some tests fail for unknown reasons.
I know it's a very old questions but the documentation on this subject is very limited so I'll post another piece of information.
This article helped me a lot: http://www.opencredo.com/2014/01/28/cucumber-android-vs-cucumber-appium/
And I used the documentation here as well (I know it's deprecated but the main project has no docs about android at all): https://github.com/mfellner/cucumber-android.
I got it to work with IntelliJ 13 Community Edition and Maven using bits from Android
Bootstrap - http://www.androidbootstrap.com/ (Mostly the Maven integration test project configuration)
Hope it helps.
I got working robotium with cucumber-jvm and androidstudio using this runner:
import android.os.Bundle;
import cucumber.api.CucumberOptions; import
cucumber.api.android.CucumberInstrumentation;
#CucumberOptions(features = {"features"}, tags = {"#smoke",
"~#pending", "~#manual", "~#reboot"})
public class Instrumentation extends CucumberInstrumentation {
private final CucumberInstrumentation instrumentationCore = new CucumberInstrumentation();
#Override
public void onCreate(final Bundle bundle) {
super.onCreate(bundle);
instrumentationCore.onCreate(bundle);
start();
}
#Override
public void onStart() {
waitForIdleSync();
instrumentationCore.start();
}
}