我试图在屏幕解锁后启动一个活动,并在下面收到错误日志。我看了关于我的问题的其他帖子,但现在他们解决了我的问题
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate receiver com.me.phone.Receive: java.lang.ClassNotFoundException: com.me.phone.Receive
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2239)
at android.app.ActivityThread.access$1600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
at java.lang.reflect.Method.invokeNative(Native Method)
Mainifest
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-feature android:name="android.hardware.camera" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.me.phone.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".Recieve" >
<intent-filter
android:enabled="true"
android:exported="false" >
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
</application>
</manifest>
收件人
package com.me.phone;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class Recieve extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent)
{
Intent activity = new Intent(context, MainActivity.class);
activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(activity);
}
}
答案 0 :(得分:2)
在你的例子中,“接收”是否拼写为两种不同的方式?
来自例外:
...java.lang.ClassNotFoundException: com.me.phone.Receive
来自清单:
<receiver android:name=".Recieve" >