Android - Activity 未找到异常错误
Android - Activity not found exception error
我收到以下错误:
android.content.ActivityNotFoundException: Unable to find explicit activity class {ie.ittralee.finalyeartest.finalyeartest/ie.ittralee.finalyeartest.finalyeartest.WiFiDirectActivity}; have you declared this activity in your AndroidManifest.xml?
现在我相信'WifiDirectActivity 应该在路径中第一个 'finalyeartest' 之后。不知道为什么有两个?
WifiDirectActivity.java
import ie.ittralee.finalyeartest.finalyeartest.DeviceListFragment.DeviceActionListener;
import static ie.ittralee.finalyeartest.finalyeartest.R.id.frag_list;
public class WiFiDirectActivity extends Activity implements ChannelListener, DeviceActionListener {
public static final String TAG = "LightShare";
private WifiP2pManager manager;
private boolean isWifiP2pEnabled = false;
private boolean retryChannel = false;
private final IntentFilter intentFilter = new IntentFilter();
private Channel channel;
private BroadcastReceiver receiver = null;
/**
* @param isWifiP2pEnabled the isWifiP2pEnabled to set
*/
public void setIsWifiP2pEnabled(boolean isWifiP2pEnabled) {
this.isWifiP2pEnabled = isWifiP2pEnabled;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...More code
如果您需要任何额外的代码,请告诉我。下面的class只是一些Wifi连接的东西,无关。希望不会...
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ie.ittralee.finalyeartest.finalyeartest">
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Google Play filtering -->
<uses-feature android:name="android.hardware.wifi.direct" android:required="true"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Light Share"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ShareFilesActivity"></activity>
<!-- Used for transferring files after a successful connection -->
<service android:enabled="true" android:name=".FileTransferService" />
</application>
</manifest>
您是否在 AndroidManifest.xml 中声明了您的 activity?
类似于以下内容:
<activity android:name=".WiFiDirectActivity"
android:theme="@style/AppTheme.NoActionBar">
</activity>
像这样将您的 activity 添加到清单中:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Light Share"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ShareFilesActivity"></activity>
<activity android:name=".WiFiDirectActivity">
<!-- Used for transferring files after a successful connection -->
<service android:enabled="true" android:name=".FileTransferService" />
</application>
修复只是在我的清单中添加 activity。以某种方式完全绕过了那个。
<activity android:name=".WiFiDirectActivity"></activity>
我收到以下错误:
android.content.ActivityNotFoundException: Unable to find explicit activity class {ie.ittralee.finalyeartest.finalyeartest/ie.ittralee.finalyeartest.finalyeartest.WiFiDirectActivity}; have you declared this activity in your AndroidManifest.xml?
现在我相信'WifiDirectActivity 应该在路径中第一个 'finalyeartest' 之后。不知道为什么有两个?
WifiDirectActivity.java
import ie.ittralee.finalyeartest.finalyeartest.DeviceListFragment.DeviceActionListener;
import static ie.ittralee.finalyeartest.finalyeartest.R.id.frag_list;
public class WiFiDirectActivity extends Activity implements ChannelListener, DeviceActionListener {
public static final String TAG = "LightShare";
private WifiP2pManager manager;
private boolean isWifiP2pEnabled = false;
private boolean retryChannel = false;
private final IntentFilter intentFilter = new IntentFilter();
private Channel channel;
private BroadcastReceiver receiver = null;
/**
* @param isWifiP2pEnabled the isWifiP2pEnabled to set
*/
public void setIsWifiP2pEnabled(boolean isWifiP2pEnabled) {
this.isWifiP2pEnabled = isWifiP2pEnabled;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...More code
如果您需要任何额外的代码,请告诉我。下面的class只是一些Wifi连接的东西,无关。希望不会...
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ie.ittralee.finalyeartest.finalyeartest">
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Google Play filtering -->
<uses-feature android:name="android.hardware.wifi.direct" android:required="true"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Light Share"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ShareFilesActivity"></activity>
<!-- Used for transferring files after a successful connection -->
<service android:enabled="true" android:name=".FileTransferService" />
</application>
</manifest>
您是否在 AndroidManifest.xml 中声明了您的 activity? 类似于以下内容:
<activity android:name=".WiFiDirectActivity"
android:theme="@style/AppTheme.NoActionBar">
</activity>
像这样将您的 activity 添加到清单中:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Light Share"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ShareFilesActivity"></activity>
<activity android:name=".WiFiDirectActivity">
<!-- Used for transferring files after a successful connection -->
<service android:enabled="true" android:name=".FileTransferService" />
</application>
修复只是在我的清单中添加 activity。以某种方式完全绕过了那个。
<activity android:name=".WiFiDirectActivity"></activity>