What is wrong in my code? 2 activity app, splash screen, webview

1k views Asked by At

Sorry, I am new to android apps. creation. I have referred pretty much all solutions but this just doesn't work...and I don't see any problem in below simple-code. My app is simple, Load the splash screen, then load the webview. What is the problem below?

ERROR I get is:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.wwes.EZEE/com.wwes.EZEE.SecondPage}; have you declared this activity in your Manifext.xml

[COMMENT] Pls. Look below, I have already declared it. what's wrong?

Files are:

  1. MainActivity.java: Here I load the splashscreen image.

    package com.example.EZEE;
    
    import com.wwes.EZEE.SecondPage;
    
    public class MainActivity extends Activity {
    @Override 
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    //Thread for displaying the Splash Screen //
    Thread splash_screen = new Thread() {
    public void  run() {
        try {
        sleep(1000);
        } catch (Exception e){
        e.printStackTrace();
        } finally {
        Intent i = new Intent(MainActivity.this, SecondPage.class);
        startActivity(i);
            }
            }
    }; splash_screen.start();
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    }
    
  2. SecondPage.java: This loads the webview.

    package com.wwes.EZEE;
    public class SecondPage extends Activity {
    WebView browserView;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    // Removed the title bare in the Application //
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_second_page);
    
    // Creation of the Webview found in the XML Layout file //
    browserView = (WebView)findViewById(R.id.webView1);
    
    // Enable Javascripts //
    browserView.getSettings().setJavaScriptEnabled(true);
    
    browserView.getSettings()....
    browserView.getSettings()....
    browserView.getSettings()....
    
    browserView.getSettings().setLoadsImagesAutomatically(true);
    
    
    // Removed both vertical and horizontal scroll bars //
    browserView.setVerticalScrollBarEnabled(false);
    browserView.setHorizontalScrollBarEnabled(false);
    browserView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    
    // Webview Wrap //
    browserView.loadUrl("http://www.ABCDE.com");
    browserView.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return false;
    }
    
    });
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    }
    
    @Override
    public void onBackPressed()
    {   if(browserView.canGoBack())
    browserView.goBack();
    else  super.onBackPressed(); } 
    

    }

  3. activity_main.xml:

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:background="#800808"
    android:scaleType="fitStart"
    android:visibility="visible"
    android:src="@drawable/logo" />
    

4) activity_second_page.xml:

    <WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:visibility="gone"
    android:layout_alignParentTop="true" />

5) manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wwes.EZEE"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />
    ----------------------------------updated----------------------------------        
    <application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.wwes.EZEERACKS.MainActivity" //// UPDATED ///
        android:configChanges="keyboard|keyboardHidden|orientation|smallestScreenSize"
        android:screenOrientation="portrait"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.wwes.EZEE.SecondPage"
        android:label="@string/title_activity_second_page" >
    </activity>

    </application>
    </manifest>

Thanks for the help!

4

There are 4 answers

18
Coderji On BEST ANSWER

how come your main activity is com.example.EZEE.MainActivity while secondPage is com.wwes.EZEE.SecondPage? I would check if both resides on the same package.

I bet if you have changed the secondPage name to com.example.EZEE.SecondPage it will work.

if it didn't work I would remove the android:name of both activity and within the "", click ctrl + space and let the eclipse handle putting the naming to the activity. therefore the shown activities are guaranteed to work in the application.

Hope this works with you, please give me a feedback.

5
EdmDroid On

You don't need the <intent-filter> tag in the SecondPage tag of the manifest because you are already starting the activity from MainActivity.

So, remove this:

<intent-filter>
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

from this:

<activity
    android:name="com.wwes.EZEE.SecondPage"
    android:label="@string/title_activity_second_page" >
    <intent-filter>
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
23
kgandroid On

Just change your defination of .SecondPage to the following in manifest.xml file

 <activity  android:name="com.wwes.EZEE.SecondPage"
              android:label="@string/title_activity_second_page" >

    </activity>
1
TAH62K On

you must defin your activity in manifest.xml file

 <activity  android:name=".SecondPage"
          android:label="@string/title_activity_second_page" >

</activity>