我的代码有什么问题?(What is wrong in my code? 2 activity app, splash screen, webview)

编程入门 行业动态 更新时间:2024-10-21 14:20:22
我的代码有什么问题?(What is wrong in my code? 2 activity app, splash screen, webview)

对不起,我是Android应用程序的新手。 创建。 我已经提到了几乎所有的解决方案,但这不起作用......我在下面的简单代码中没有看到任何问题。 我的应用很简单,加载启动画面,然后加载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

文件是:

MainActivity.java:在这里我加载了splashscreen图像。

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

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

Files are:

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

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(); }

}

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!

最满意答案

为什么你的主要活动是com.example.EZEE.MainActivity而secondPage是com.wwes.EZEE.SecondPage ? 我会检查两者是否都在同一个包装上。

我打赌,如果你已经将第二页的名称改为com.example.EZEE.SecondPage ,它将起作用。

如果它不起作用,我会删除android:name两个活动的android:name ,在“”中,单击ctrl + space ,让eclipse句柄将命名放到活动中。 因此,所显示的活动保证在应用程序中起作用。

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

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.

更多推荐

本文发布于:2023-07-24 10:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1244984.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   代码   code   wrong   activity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!