即使在清单中声明了活动也未找到异常

时间:2012-12-15 08:04:13

标签: java android eclipse thread-safety avd

这是我的logcat文件,显示活动未找到异常,即使我已在清单文件中声明它。每当我在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代码和清单文件如下所示

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

清单文件

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

3 个答案:

答案 0 :(得分:4)

写下面的代码

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>

它将解决您的问题。

答案 1 :(得分:3)

您似乎忘了将intent-filter标记添加到第二个活动。请尝试以下明显更改

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

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

答案 2 :(得分:2)

我知道我迟到了,但它可以帮助别人。 只需添加此

Intent mInSelection=new Intent(MainActivity.this,my.example.myproject.SELECTION.class);
startActivity(mInSelection);

它肯定会帮助你。

相关问题