12
Янв
2018

class cannot be instantiated

Решил доработать старый проект ,под новые версии android 7,8. Проект открыл в android studio 3.0 - подстроил проект под android studio 3.0 ,проект собирается и компилируется без ошибок,но когда запускаю apk файл на устройстве. В лог пишется вот эта ошибка :

01 - 12 01: 47: 22.910 1811 - 1811 / ? E / AndroidRuntime : FATAL EXCEPTION: main
Process: com.android.locktest.lockscreen, PID: 1811
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo {
  com.android.locktest.lockscreen / com.screen.locktest.lockscreen.LockScreenActivity
}: java.lang.InstantiationException: class com.screen.locktest.lockscreen.LockScreenActivity cannot be instantiated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2360)
at android.app.ActivityThread.access$800(ActivityThread.java: 144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1278)
at android.os.Handler.dispatchMessage(Handler.java: 102)
at android.os.Looper.loop(Looper.java: 135)
at android.app.ActivityThread.main(ActivityThread.java: 5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java: 372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 694)
Caused by: java.lang.InstantiationException: class com.screen.locktest.lockscreen.LockScreenActivity cannot be instantiated
at java.lang.Class.newInstance(Class.java: 1553)
at android.app.Instrumentation.newActivity(Instrumentation.java: 1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2199)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2360) 
at android.app.ActivityThread.access$800(ActivityThread.java: 144) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1278) 
at android.os.Handler.dispatchMessage(Handler.java: 102) 
at android.os.Looper.loop(Looper.java: 135) 
at android.app.ActivityThread.main(ActivityThread.java: 5221) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java: 372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 899) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 694) 
01 - 12 01: 57: 49.896 2089 - 2089 / com.android.locktest.lockscreen E / AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.locktest.lockscreen, PID: 2089
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo {
  com.android.locktest.lockscreen / com.screen.locktest.lockscreen.LockScreenActivity
}: java.lang.InstantiationException: class com.screen.locktest.lockscreen.LockScreenActivity cannot be instantiated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2360)
at android.app.ActivityThread.access$800(ActivityThread.java: 144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1278)
at android.os.Handler.dispatchMessage(Handler.java: 102)
at android.os.Looper.loop(Looper.java: 135)
at android.app.ActivityThread.main(ActivityThread.java: 5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java: 372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 694)
Caused by: java.lang.InstantiationException: class com.screen.locktest.lockscreen.LockScreenActivity cannot be instantiated
at java.lang.Class.newInstance(Class.java: 1553)
at android.app.Instrumentation.newActivity(Instrumentation.java: 1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2199)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2360) 
at android.app.ActivityThread.access$800(ActivityThread.java: 144) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1278) 
at android.os.Handler.dispatchMessage(Handler.java: 102) 
at android.os.Looper.loop(Looper.java: 135) 
at android.app.ActivityThread.main(ActivityThread.java: 5221) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java: 372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 899) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 694)

Я так понимаю ошибка кроется тут ,но как исправить не знаю.

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo {
  com.android.locktest.lockscreen / com.screen.locktest.lockscreen.LockScreenActivity
}: java.lang.InstantiationException: class com.screen.locktest.lockscreen.LockScreenActivity cannot be instantiated

Вот манифест :

<< ? 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.android.locktest.lockscreen"
tools: ignore = "ExtraText" >

  <
  uses - permission android: name = "android.permission.DISABLE_KEYGUARD" / >
  <
  uses - permission android: name = "android.permission.WAKE_LOCK" / >
  <
  uses - permission android: name = "android.permission.RECEIVE_BOOT_COMPLETED" / >
  <
  uses - permission android: name = "android.permission.READ_PHONE_STATE" / >
  <
  uses - permission android: name = "android.permission.SYSTEM_ALERT_WINDOW" / >

  <
  application

android: label = "@string/app_name"
android: name = "android.support.multidex.MultiDexApplication" >

  <
  activity android: name = "com.screen.locktest.lockscreen.LockScreenActivity"
android: excludeFromRecents = "true"
android: label = "@string/app_name"
android: launchMode = "singleTask"
android: screenOrientation = "portrait"
android: theme = "@android:style/Theme.NoTitleBar.Fullscreen" >
  <
  intent - filter >
  <
  action android: name = "android.intent.action.MAIN" / >
  <
  category android: name = "android.intent.category.LAUNCHER" / >
  <
  /intent-filter> <
  /activity> <
  service
android: name = "com.screen.locktest.lockscreen.LockscreenService" / >


  <
  receiver android: name = "com.screen.locktest.lockscreen.LockscreenIntentReceiver" >



  <
  intent - filter >
  <
  action android: name = "android.intent.action.BOOT_COMPLETED" / >
  <
  /intent-filter> <
  /receiver> <
  /application> <
  /manifest>

Вот файл build.Gradle

apply plugin: 'com.android.application'

android {
  aaptOptions.cruncherEnabled = false
  aaptOptions.useNewCruncher = false
  compileSdkVersion 27
  buildToolsVersion '26.0.2'

  defaultConfig {
    multiDexEnabled true
    minSdkVersion 19
    targetSdkVersion 27

  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }


  compileOptions {
    targetCompatibility 1.8
    sourceCompatibility 1.8
  }
}

dependencies {
  implementation 'com.android.support:multidex:1.0.2'
  implementation 'com.android.support:appcompat-v7:27.0.2'
  implementation 'com.android.support.constraint:constraint-layout:1.0.2'
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'com.android.support.test:runner:1.0.1'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Помогите пожалуйста.

Источник: https://ru.stackoverflow.com/questions/769710/class-cannot-be-instantiated

Тебе может это понравится...

Добавить комментарий