0

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 Answers4

10

you must defin your activity in manifest.xml file

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

</activity>
TAH62K
  • 421
  • 2
  • 12
1

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>
EdmDroid
  • 1,350
  • 1
  • 11
  • 25
0

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>
kgandroid
  • 5,507
  • 5
  • 39
  • 69
  • See above. I already have exact same definition in my manifest.xml file. – user3673408 May 26 '14 at 06:18
  • Delete the part or change it to – kgandroid May 26 '14 at 06:21
  • I have already tried deleting the but see same error. – user3673408 May 26 '14 at 06:34
  • I can see that your updated manifest.xml still contain the tag while defining the second page!!??? – kgandroid May 26 '14 at 06:36
  • its removed in my project but was mistakenly here in the post. I have now removed it from post also – user3673408 May 26 '14 at 06:39
  • ok.Now if you are getting the same error i can suggest you one thing.Pull your MainActivity from the package com.example.EZEE to the package com.wwes.EZEE;and then change the definition of MainActivity in manifest as: android:name="com.wwes.EZEE.MainActivity" – kgandroid May 26 '14 at 06:43
  • Ok I just moved the public class Mainactivity extends Activty {//} to SecondPage.java It gives me error telling "Public type mainActivity" must be defined in its own file – user3673408 May 26 '14 at 07:05
  • nono you are getting me wrong.According to you code you have must have two packages:com.example.EZEE and com.wwes.EZEE;I am just telling to move MainActivity class to the later package.And then please delete the MainActivity within com.example.EZEE package – kgandroid May 26 '14 at 07:08
  • Yes, I understand that. I have just moved the MainActivity class from com.example.EZEE to com.wwes.EZEE. What about the run(), onCreate() and OncreateOptionsMenu() functions, I cant retain them in mainActivity.java, correct? So what code will my MainActivity.java file have? – user3673408 May 26 '14 at 07:14
  • You do not need to worry about them.Just rt click on MainActivity->copy and paste it in your com.wwes.EZEE; package.Remove the mainactivity from the older one.and dont forget to update manifest as: android:name="com.wwes.EZEE.MainActivity" .It should work. – kgandroid May 26 '14 at 07:16
  • In manifest.xml, i made following change to: – user3673408 May 26 '14 at 07:36
  • it seems that Everything is now perfect.Clean your project and run. – kgandroid May 26 '14 at 07:45
  • I did Project --> Clean and re-ran directly to test on the samsung phone.. Same error Unable to find explicit activity class {com.wwes.EZEE/com.wwes.EZEE.SecondPage} :-( BTW, in manifest.xml, I have the following intact: android:name=".SecondPage" android:label="@string/title_activity_second_page"> – user3673408 May 26 '14 at 07:50
  • Please see above, updated line added to manifest.xml as ////UPDATED //// Rest of the file is the same. – user3673408 May 26 '14 at 08:07
  • Why should the package name be updated? Shouldn't it remain as: package="com.wwes.EZEE"? – user3673408 May 26 '14 at 08:21
  • I am talking about the first line in your mainactivity class.Is it package com.wwes.EZEE?? – kgandroid May 26 '14 at 08:22
  • Yes, thats correct. ist few lines of my MainActivity.java are: package com.wwes.EZEE; import com.wwes.EZEE.SecondPage; import com.wwes.EZEE.R; – user3673408 May 26 '14 at 08:30
  • Remove import com.wwes.EZEE.R; – kgandroid May 26 '14 at 08:31
  • removed it an ran on Samsung phone Same error: FATAL EXCEPTION pointing to have you declared this activity in manifest.xml as {com.wwes.EZEE/com.wwes.EZEE.SecondPage}. I wonder whats going wrong? – user3673408 May 26 '14 at 08:36
  • Do you know how to debug??then put a breakpoing in the button and debug it.There must be some silly mistake. – kgandroid May 26 '14 at 08:38
  • No. Not really. But definitely some very obvious mistake, I cant seem to catch...BTW when i ran in debug-mode (i.e: debug) on my phone, it didnt crash. But it didnt even proceed ahead of the Splash Screen. – user3673408 May 26 '14 at 08:46
  • hi kgandroid- moving files to com.wwes.EZEE did'nt work. but yes, if move them to com.example.EZEE started working. I anyways had lots of issues related to R could not be resolved. Hence, i created fresh project & had only 1-package this time with those 2 files & now it works fine. Ofcoz, there are some cosmetic glitches like white-screen etc but now it works. Thanks – user3673408 May 26 '14 at 12:13
  • yahh...thats the main thing...moving two files in one package. – kgandroid May 26 '14 at 12:14
0

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.

Coderji
  • 7,655
  • 5
  • 37
  • 51
  • Yes, I have both "com.example.EZEE.MainActivity" and "com.wwes.EZEE.SecondPage" under the same Package named: EZEE. So in my package explorer i see. EZEE --> src --> com.example.EZEE and src --> com.wwes.EZEE – user3673408 May 26 '14 at 07:56
  • Ok now what i have done is moved the MainActivity.java file under "com.wwes.EZEE" and removed it from "com.example.EZEE" – user3673408 May 26 '14 at 07:59
  • by doing so, is the application launching? – Coderji May 26 '14 at 08:01
  • I believe you should move the `SecondPage.java` to `com.example.EZEE` and change the manifest to `android:name:com.example.EZEE.SecondPage` – Coderji May 26 '14 at 08:03
  • Yes, the application launches, I see the spalsh Scree Image, but ends with an ERROR on phone " The application now has to close and exits" – user3673408 May 26 '14 at 08:09
  • I will try now. Someone here suggested to move MainActivity.java to "com.wwes.EZEE" & made appropriate changes in manifest.xml but failed with same error: ActivityNotFoundException: Unable to find explicit activity class {com.wwes.EZEE/com.wwes.EZEE.SecondPage – user3673408 May 26 '14 at 08:14
  • Ok now my "com.example.EZEE" has both files: MainActivity.java and SecondPage.java. So in my manifest.xml, now I should only have "android:name:com.example.EZEE.SecondPage" activity and remove the other SeconPage activity, correct? – user3673408 May 26 '14 at 08:19
  • ya you should only have 2 activities with the name of: `android:name:com.example.EZEE.MainActivity` and `android:name:com.example.EZEE.SecondPage` – Coderji May 26 '14 at 08:27
  • BTW, even if i were to move the other way around.i.e both the .java files into "com.wwes.EZEE", it should work, isnt it? – user3673408 May 26 '14 at 08:50
  • no i dont think so because you are moving both files to package -> package. not to the main package – Coderji May 26 '14 at 08:59
  • Thanks. But moving both files to "com.wwes.EZEE" doesnt work. Still same FATAL EXCEPTION error, consistently pointing to if [com.wwes.EZEE/com.wwes.EZEE.SecondPage} has been defined in manifext.xml or not... Its mind-boggling as to whats going wrong here .... :-( – user3673408 May 26 '14 at 09:02
  • I told you to move them both to `com.example.EZEE` – Coderji May 26 '14 at 09:04
  • I now have a problem starting Eclipse.. Earlier i ran in DEBUG mode and after debugging just shut it. Now whenever i open eclipse, by default it opens in DEBUG ADT mode and goes in to NOT responding state.. waited for 30mins after opening eclipse but cant proceed. would u know how to get past this? Thnks alot for ur help – user3673408 May 26 '14 at 09:48
  • Ok i have now sorted out the Eclipse startup problem.. Now will make changes as you suggested, will run & update you ... – user3673408 May 26 '14 at 10:12
  • Ok, I moved both files to: com.example.EZEE. I now have 6 errors, pointing to "R cannot be resolved to a variable".. one of them is pointing to : setContentView(R.layout.activity_second_page); – user3673408 May 26 '14 at 10:43
  • 1
    Hi Coderji- Finally I have something working. I created a complete fresh project & now i only have 1 -single package consisting of those 2 java files. Now, the Splash-screen image loads and then it goes to the second-page activity. However, in the webview doesn't open, its just a blank-white-screen. On the logcat, I see the ERROR: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length. Any ideas on solving this? – user3673408 May 26 '14 at 11:52
  • glad I was able to help, I have never passed this issue before but after googling it, I dont think it is related to webview. refer to the is [question](http://stackoverflow.com/questions/13670374/android-span-exclusive-exclusive-spans-cannot-have-a-zero-length) hope it can help you out – Coderji May 26 '14 at 15:47
  • Yes, thanks I read that thread which internally had some more weblinks to read & figured out that its not a problem in the code but inside android native code-base. – user3673408 May 26 '14 at 16:41