The code is all about taking the zodiac sign as the input in the 1st activity and when clicked OK navigates to the next activity where it displays the details as the web view of that particular zodiac sign. When ever I try to run the code in the emulator or in my mobile I get a warning project is continuously stopping and the application closes.
MainActivity.java
package com.example.project;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.webkit.WebView;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void send(View v){
Intent goToSecond = new Intent();
goToSecond.setClass(this, SecondActivity.class);
startActivity(goToSecond);
String sign = ((EditText)(findViewById(R.id.editText_sign))).getText().toString();
goToSecond.putExtra("sign", sign);
startActivity(goToSecond);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
tools:context=".MainActivity"
tools:ignore="Autofill"
android:background="@drawable/signwheel2">
<TextView
android:id="@+id/textView"
android:layout_width="56dp"
android:layout_height="wrap_content"
android:layout_marginStart="55dp"
android:background="#EFE9E9"
android:text="@string/zodiac" />
<EditText
android:id="@+id/editText_sign"
android:layout_width="223dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:background="#FDFCFC"
android:ems="10"
android:hint="@string/libra"
android:inputType="textPersonName" />
<Button
android:id="@+id/button2"
android:layout_width="127dp"
android:layout_height="wrap_content"
android:onClick="send"
android:text="@android:string/ok"
android:visibility="visible" />
</LinearLayout>
SecondActivity.java
package com.example.project;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Toast;
public class SecondActivity extends AppCompatActivity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
webView = findViewById(R.id.webview);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent caller = getIntent();
String sign = caller.getStringExtra("sign");
assert sign != null;
switch (sign) {
case "Taurus":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/taurus-zodiac-sign/");
break;
case "Aries":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/aries-zodiac-sign/");
break;
case "Leo":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/leo-zodiac-sign/");
break;
case "Pisces":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/pisces-zodiac-sign/");
break;
case "Scoripo":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/scorpio-zodiac-sign/");
break;
case "Sagittarius":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/sagittarius-zodiac-sign/");
break;
case "Gemini":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/gemini-zodiac-sign/");
break;
case "Virgo":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/virgo-zodiac-sign/");
break;
case "Libra":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/libra-zodiac-sign/");
break;
case "Capricorn":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/capricorn-zodiac-sign/");
break;
case "Aquarius":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/aquarius-zodiac-sign/");
break;
case "Cancer":
webView.loadUrl("https://www.chatelaine.com/living/horoscopes/cancer-zodiac-sign/");
break;
default:
String message1 = "Please check the spelling";
Toast.makeText(getApplicationContext(), message1, Toast.LENGTH_LONG).show();
break;
}
}
}
activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity">
<WebView
android:id="@+id/webview"
android:layout_width="409dp"
android:layout_height="729dp"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.project">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SecondActivity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Logcat:
04-22 14:59:17.888 3355-3355/? I/art: Not late-enabling -Xcheck:jni (already on)
04-22 14:59:18.026 3355-3355/com.example.project W/System: ClassLoader referenced unknown path:
/data/app/com.example.project-2/lib/x86
04-22 14:59:18.045 3355-3355/com.example.project D/AndroidRuntime: Shutting down VM
04-22 14:59:18.046 3355-3355/com.example.project E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.project, PID: 3355
java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider:
java.lang.IllegalStateException:
******************************************************************************
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers *
* should follow the instructions here: *
* https://googlemobileadssdk.page.link/admob-android-update-manifest *
* to add a valid App ID inside the AndroidManifest. *
* Google Ad Manager publishers should follow instructions here: *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest. *
******************************************************************************
at android.app.ActivityThread.installProvider(ActivityThread.java:5156)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException:
******************************************************************************
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers *
* should follow the instructions here: *
* https://googlemobileadssdk.page.link/admob-android-update-manifest *
* to add a valid App ID inside the AndroidManifest. *
* Google Ad Manager publishers should follow instructions here: *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest. *
******************************************************************************
at com.google.android.gms.internal.ads.zzyc.attachInfo(com.google.android.gms:play-services-ads-
lite@@19.1.0:33)
at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-
services-ads-lite@@19.1.0:3)
at android.app.ActivityThread.installProvider(ActivityThread.java:5153)
... 10 more
04-22 14:59:20.745 3355-3355/? I/Process: Sending signal. PID: 3355 SIG: 9