java - 即使在 list 中声明 Activity 也未找到异常

标签 java android eclipse thread-safety android-virtual-device

这是我的 logcat 文件,它显示 Activity 未找到异常,即使我已在 list 文件中声明它。每当我在 eclipse avd 中启动我的应用程序时,都会弹出“不幸已停止”警告。请帮我解决这个问题。

12-15 07:42:47.833: E/AndroidRuntime(770): FATAL EXCEPTION: Thread-75
12-15 07:42:47.833: E/AndroidRuntime(770): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=my.example.myproject.SELECTION }
12-15 07:42:47.833: E/AndroidRuntime(770):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
12-15 07:42:47.833: E/AndroidRuntime(770):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
12-15 07:42:47.833: E/AndroidRuntime(770):  at android.app.Activity.startActivityForResult(Activity.java:3370)
12-15 07:42:47.833: E/AndroidRuntime(770):  at android.app.Activity.startActivityForResult(Activity.java:3331)
12-15 07:42:47.833: E/AndroidRuntime(770):  at android.app.Activity.startActivity(Activity.java:3566)
12-15 07:42:47.833: E/AndroidRuntime(770):  at android.app.Activity.startActivity(Activity.java:3534)
12-15 07:42:47.833: E/AndroidRuntime(770):  at my.example.myproject.FullscreenActivity$3.run(FullscreenActivity.java:72)

Java代码和 list 文件如下所示

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);
        final View controlsView = findViewById(R.id.fullscreen_content_controls);
        final View contentView = findViewById(R.id.fullscreen_content);
        iol = (Button)findViewById(R.id.iolCalculation);
        help = (Button)findViewById(R.id.sHelp);
        about = (Button)findViewById(R.id.sAbout);
        Thread iolthread=new Thread(){
            public void run(){
                try{
                    iol.setOnClickListener(new View.OnClickListener() {


                            @Override
                            public void onClick(View v) {
                                // TODO Auto-generated method stub
                                setContentView(R.layout.selection);
                            }
                    });
                    Intent iolIntent=new Intent("my.example.myproject.SELECTION");
                    startActivity(iolIntent);
                }
                finally{
                    finish();
                }
            }
        };  
        iolthread.start();

list 文件

<application
        android:allowBackup="true"
        android:theme="@style/AppTheme">"
        <activity
            android:name=".FullscreenActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Selection"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >

                <action android:name="my.example.myproject.SELECTION" />

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

        </activity>
    </application>

我是 android 编程和堆栈溢出的初学者。如果有任何错误,请原谅我。 下面是我的主要 xml 文件

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black"
    tools:context=".FullscreenActivity" >

    <!--
         The primary full-screen view. This can be replaced with whatever view
         is needed to present your content, e.g. VideoView, SurfaceView,
         TextureView, etc.
    -->

    <TextView
        android:id="@+id/fullscreen_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:keepScreenOn="true"/>

    <!--
         This FrameLayout insets its children based on system windows using
         android:fitsSystemWindows.
    -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/Black"
        android:fitsSystemWindows="true" >

        <LinearLayout
            android:id="@+id/fullscreen_content_controls"
            style="?buttonBarStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/black_overlay"
            android:orientation="horizontal"
            tools:ignore="UselessParent" >
        </LinearLayout>

        <Button
            style="@style/ButtonBarButton"
            android:layout_width="222dp"
            android:layout_height="62dp"
            android:layout_marginLeft="45dp"
            android:layout_marginTop="75dp"
            android:background="@color/black"
            android:paddingLeft="20dp"
            android:id="@+id/iolCalculation"
            android:text="@string/Button"
            android:textColor="@color/WhiteSmoke"
            android:textStyle="bold" />

        <Button
            style="@style/ButtonBarButton"
            android:layout_width="222dp"
            android:layout_height="62dp"
            android:layout_marginLeft="45dp"
            android:id="@+id/sHelp"
            android:layout_marginTop="139dp"
            android:background="@color/Black"
            android:gravity="center"
            android:paddingLeft="10dp"
            android:text="@string/Button1"
            android:textColor="@color/WhiteSmoke"
            android:textStyle="bold" />

        <Button
            style="@style/ButtonBarButton"
            android:layout_width="222dp"
            android:layout_height="62dp"
            android:id="@+id/sAbout"
            android:layout_marginLeft="45dp"
            android:layout_marginTop="203dp"
            android:background="@color/Black"
            android:paddingLeft="10dp"
            android:text="@string/Button2"
            android:textColor="@color/WhiteSmoke"
            android:textStyle="bold" >

        </Button>
</FrameLayout>

</FrameLayout>

最佳答案

写下代码

Intent mInSelection=new Intent(MainActivity.this,Selection.class);
startActivity(mInSelection);

代替

Intent iolIntent=new Intent("my.example.myproject.SELECTION");
startActivity(iolIntent);

并将以下代码写入您的 manifest.xml 文件

<activity
    android:name=".Selection"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

代替

<activity
    android:name=".Selection"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@style/FullscreenTheme" >

    <action android:name="my.example.myproject.SELECTION" />

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

</activity>

它将解决您的问题。

关于java - 即使在 list 中声明 Activity 也未找到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13890486/

相关文章:

java - Selenium : How to stop geckodriver process impacting PC memory, 不调用 driver.quit()?

java - 方向更改后按钮和菜单停止工作

android - 自动更改ListView的背景图片

Android - 在 LinearLayout 或 RelativeLayout 中为 View 的 topMargin/bottomMargin/等设置动画

java - 强化与 Maven 的集成 - 安装

java - 关于在Eclipse中添加库

java - 为什么在使用 += 将整数连接到字符串时 g++ 不发出警告/错误

android - 如何在不使用 phonegap 的情况下在我的 android 应用程序中实现二维码阅读器?

java - 如何从 eclipse 获取实体的图标?

java - Android 确保 HTTP 响应到达