I have a very simple android application for loan calculations. I'm using this to learn how to program a larger scale program i'm working on. I've used the development pages from Android and AdMob, but I cannot seem to get the advert to show at the top of the app.
I have the following files MainActivity.java, activity_main.xml
activity_main.xml is as follows
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".LoanCalculator" >
<EditText
android:id="@+id/editBalance"
android:layout_width="80dp"
android:layout_height="30dp"
android:layout_alignBottom="@+id/balance"
android:layout_alignParentRight="true"
android:layout_marginRight="17dp"
android:ems="10"
android:textSize="10dp"
android:inputType="number" >
</EditText>
<TextView
android:id="@+id/rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/balance"
android:layout_below="@+id/balance"
android:layout_marginTop="30dp"
android:text="Rate (APR)" />
<EditText
android:id="@+id/editRate"
android:layout_width="80dp"
android:layout_height="30dp"
android:layout_alignBottom="@+id/rate"
android:layout_alignParentRight="true"
android:layout_marginRight="17dp"
android:ems="10"
android:textSize="10dp"
android:inputType="number|numberDecimal" >
</EditText>
<TextView
android:id="@+id/term"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/rate"
android:layout_below="@+id/rate"
android:layout_marginTop="30dp"
android:text="Term (Mo.)" />
<EditText
android:id="@+id/editTerm"
android:layout_width="80dp"
android:layout_height="30dp"
android:layout_alignBottom="@+id/term"
android:layout_alignParentRight="true"
android:layout_marginRight="17dp"
android:ems="10"
android:textSize="10dp"
android:inputType="number" >
</EditText>
<TextView
android:id="@+id/payment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/term"
android:layout_below="@+id/term"
android:layout_marginTop="30dp"
android:text="Monthly Payment" />
<TextView
android:id="@+id/textMntlypmt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/payment"
android:layout_alignBottom="@+id/payment"
android:layout_alignLeft="@+id/editTerm"
android:layout_alignRight="@+id/editTerm"
android:text="" />
<Button
android:id="@+id/calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/payment"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:onClick="ButtonOnClick"
android:text="Calculate" />
<TextView
android:id="@+id/balance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/adView"
android:layout_below="@+id/adView"
android:layout_marginTop="20dp"
android:text="Balance" />
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-2754978410424403/9803362252"
ads:loadAdOnCreate="true" >
</com.google.ads.AdView>
</RelativeLayout>
My .java is:
package biz.midl.loancalculator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
public class MainActivity extends Activity implements OnClickListener {
Button Home;
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void ButtonOnClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.calculate:
EditText myEdit = (EditText) findViewById(R.id.editBalance);
String myEditValue = myEdit.getText().toString();
double loanAmount = Double.parseDouble(myEditValue);
EditText myEdit2 = (EditText) findViewById(R.id.editRate);
String myEditValue2 = myEdit2.getText().toString();
double interestRate = Double.parseDouble(myEditValue2);
EditText myEdit3 = (EditText) findViewById(R.id.editTerm);
String myEditValue3 = myEdit3.getText().toString();
Double loanPeriod = Double.parseDouble(myEditValue3);
double r = interestRate/1200;
double r1 = Math.pow(r+1,loanPeriod);
double editMnthlypmt = (double) ((r+(r/(r1-1))) * loanAmount);
TextView textMnthlypmt = (TextView)findViewById(R.id.textMntlypmt);
textMnthlypmt.setText("" + String.valueOf(editMnthlypmt));
break;
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
any suggestions would be appreciated.
Error is as follows:
The application Loan Calculator (process.....) has stopped unexpectedly.
LogCats are as follows:
09-18 03:32:47.534: D/AndroidRuntime(335): Shutting down VM
09-18 03:32:47.534: W/dalvikvm(335): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-18 03:32:47.594: E/AndroidRuntime(335): FATAL EXCEPTION: main
09-18 03:32:47.594: E/AndroidRuntime(335): java.lang.RuntimeException: Unable to start activity ComponentInfo{biz.midl.loancalculator/biz.midl.loancalculator.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class com.google.ads.AdView
09-18 03:32:47.594: E/AndroidRuntime(335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.os.Handler.dispatchMessage(Handler.java:99)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.os.Looper.loop(Looper.java:123)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-18 03:32:47.594: E/AndroidRuntime(335): at java.lang.reflect.Method.invokeNative(Native Method)
09-18 03:32:47.594: E/AndroidRuntime(335): at java.lang.reflect.Method.invoke(Method.java:521)
09-18 03:32:47.594: E/AndroidRuntime(335): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-18 03:32:47.594: E/AndroidRuntime(335): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-18 03:32:47.594: E/AndroidRuntime(335): at dalvik.system.NativeStart.main(Native Method)
09-18 03:32:47.594: E/AndroidRuntime(335): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class com.google.ads.AdView
09-18 03:32:47.594: E/AndroidRuntime(335): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-18 03:32:47.594: E/AndroidRuntime(335): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.app.Activity.setContentView(Activity.java:1647)
09-18 03:32:47.594: E/AndroidRuntime(335): at biz.midl.loancalculator.MainActivity.onCreate(MainActivity.java:23)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-18 03:32:47.594: E/AndroidRuntime(335): ... 11 more
09-18 03:32:47.594: E/AndroidRuntime(335): Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView in loader dalvik.system.PathClassLoader[/data/app/biz.midl.loancalculator-1.apk]
09-18 03:32:47.594: E/AndroidRuntime(335): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
09-18 03:32:47.594: E/AndroidRuntime(335): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
09-18 03:32:47.594: E/AndroidRuntime(335): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
09-18 03:32:47.594: E/AndroidRuntime(335): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
09-18 03:32:47.594: E/AndroidRuntime(335): ... 20 more