我收到以下错误:
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
如果您需要任何额外的代码,请告诉我们。上面的类下面只是一些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>
答案 0 :(得分:1)
将您的活动添加到清单中,如下所示:
<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>
答案 1 :(得分:0)
修复只是在我的清单中添加活动。完全被某种方式绕过了。
<activity android:name=".WiFiDirectActivity"></activity>
答案 2 :(得分:-1)
你是否在AndroidManifest.xml中声明了你的活动? 如下所示:
<activity android:name=".WiFiDirectActivity"
android:theme="@style/AppTheme.NoActionBar">
</activity>