【问题标题】:What is wrong in my code? 2 activity app, splash screen, webview我的代码有什么问题? 2 活动应用程序、闪屏、webview
【发布时间】:2014-05-26 03:37:38
【问题描述】:

抱歉,我是安卓应用的新手。创建。我已经提到了几乎所有的解决方案,但这只是行不通……而且我在下面的简单代码中看不到任何问题。我的应用程序很简单,加载启动画面,然后加载 webview。下面是什么问题?

我得到的错误是:

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

[评论]请。看下面,我已经声明过了。怎么了?

文件是:

  1. MainActivity.java:在这里我加载启动画面图像。

    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:这会加载 web 视图。

    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>

感谢您的帮助!

【问题讨论】:

  • secondPage活动中移除标签并告诉我结果..
  • 你能把你所有的manifest.xml贴出来吗?我需要看看你的包名。
  • 更新了我的 manifest.xml。请检查-谢谢

标签: android webview splash-screen activitynotfoundexception


【解决方案1】:

您必须在 manifest.xml 文件中定义您的活动

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

</activity>

【讨论】:

  • 请见上文。我的 manifest.xml 已经有了活动的定义。
【解决方案2】:

您不需要清单的 SecondPage 标记中的 &lt;intent-filter&gt; 标记,因为您已经从 MainActivity 开始活动。

所以,删除这个:

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

从此:

<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>

【讨论】:

  • 我尝试了您删除 的建议。不工作。我得到同样的错误。
  • 你能发布整个 manifest.xml吗? (我的意思是从清单开始标签到清单结束标签)
  • 从顶部的manifest 标记中删除package="com.wwes.EZEE"
  • 现在它在第 # 行出现以下错误 (
  • 那么我想你需要在com.example.EZEEcom.wwes.EZEE 中都有MainActivitySecondPage
【解决方案3】:

为什么你的主要活动是com.example.EZEE.MainActivity 而第二页是com.wwes.EZEE.SecondPage?我会检查两者是否位于同一个包中。

我敢打赌,如果您将 secondPage 名称更改为 com.example.EZEE.SecondPage,它将起作用。

如果它不起作用,我将删除两个活动和“”内的android:name,单击ctrl + space 并让 eclipse 处理将命名放入活动。因此显示的活动保证在应用程序中工作。

希望这对你有用,请给我反馈。

【讨论】:

  • 是的,我在同一个名为 EZEE 的包下同时拥有“com.example.EZEE.MainActivity”和“com.wwes.EZEE.SecondPage”。所以在我的包资源管理器中我看到了。 EZEE --> src --> com.example.EZEE 和 src --> com.wwes.EZEE
  • 好的,现在我所做的是将 MainActivity.java 文件移到“com.wwes.EZEE”下并将其从“com.example.EZEE”中删除
  • 这样,应用启动了吗?
  • 我认为您应该将SecondPage.java 移动到com.example.EZEE 并将清单更改为android:name:com.example.EZEE.SecondPage
  • 嗨 Coderji- 最后我有一些工作。我创建了一个完整的新项目,现在我只有 1 个由这 2 个 java 文件组成的包。现在,启动画面图像加载,然后进入第二页活动。但是,在 webview 中没有打开,它只是一个空白屏幕。在 logcat 上,我看到 ERROR: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length。有解决这个问题的想法吗?
【解决方案4】:

只需将 .SecondPage 的定义更改为 ma​​nifest.xml 文件中的以下内容

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

    </activity>

【讨论】:

  • 见上文。我的 manifest.xml 文件中已经有了完全相同的定义。
  • 删除部分或改成跨度>
  • 我已经尝试删除 但看到同样的错误。
  • 我可以看到您更新的 manifest.xml 在定义第二页时仍然包含 标记!!???
  • 它在我的项目中被删除,但在帖子中被错误地放在此处。我现在也把它从帖子中删除了
猜你喜欢
  • 2015-06-04
  • 1970-01-01
  • 2020-07-20
  • 1970-01-01
  • 1970-01-01
  • 2018-12-17
  • 1970-01-01
  • 1970-01-01
  • 2017-04-08
相关资源
最近更新 更多