我正在处理通知,因此我想在调用oncreate方法时在启动应用程序中创建频道。 所以当我在应用程序类的应用程序标记中添加应用程序类的名称时。 当我删除它运行良好。 当有人进入该区域时,我将使用通知进行地理围栏,它将生成通知。
请帮助我...如果可以的话。
最明显的文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.googlemap">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashscreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Notification.NotificationActivity"></activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"></activity>
<service android:name=".service.GeofenceTrasitionService" />
</application>
</manifest>
'''
应用程序文件
package com.example.googlemap;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
public class App extends Application{
public static final String CHANNEL_1_ID = "channel1";
public static final String CHANNEL_2_ID = "channel2";
@Override
public void onCreate() {
super.onCreate();
createChannels();
}
private void createChannels() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channel1 = new NotificationChannel(
CHANNEL_1_ID,
"Channel 1",
NotificationManager.IMPORTANCE_HIGH);
channel1.setDescription("This is channel 1");
NotificationChannel channel2 = new NotificationChannel(
CHANNEL_2_ID,
"Channel 2",
NotificationManager.IMPORTANCE_LOW);
channel2.setDescription("This is channel 2");
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel1);
manager.createNotificationChannel(channel2);
}
}
}
错误
07-18 16:08:39.937 3147-3147/com.example.googlemap E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.googlemap, PID: 3147
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.googlemap/com.example.googlemap.SplashscreenActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.googlemap.SplashscreenActivity" on path: DexPathList[[zip file "/data/app/com.example.googlemap-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.googlemap-2, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2119)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2243)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5019)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.googlemap.SplashscreenActivity" on path: DexPathList[[zip file "/data/app/com.example.googlemap-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.googlemap-2, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
答案 0 :(得分:0)
我认为问题出在 SplashscreenActivity
在清单中的启动器活动中定义 SplashscreenActivity 时,但没有找到该类。
请检查** SplashscreenActivity **是否存在。
答案 1 :(得分:0)
我通过在Application类中添加此函数来消除此错误。 我试过了,幸运的是它运行得很好...
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}