2012-12-15 56 views
1

這是我的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) 

被如下所示

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

清單文件

Java代碼和清單文件

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

都是在同一個包中的活動。 –

+0

@SahilMahajanMj yup一切都在同一包 – human

+0

@AhamBrahmaasmi:然後Dipak的回答可以很好地解決您的問題。 –

回答

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> 

它會解決你的問題。

+0

你是否積累了兩個以上的答案? –

+0

沒問題。其中一個答案已被刪除。但要確保在發佈新的答案之前查看其他答案。 :) –

+0

嘗試過但din工作:( – human

3

看起來你忘了意圖過濾器標籤添加到第二個活動。試試下面的清單變化

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

嘗試過,但叮噹作響! – human

2

我知道我遲到了,但它可以幫助別人。 只需添加該產品

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

它一定會幫助你。

相關問題