I'm using build tools 30.0.3 and API level 30, with multidex enabled and imported in gradle
I have an Activity which is declared in my manifest like so
<activity
android:name="com.weare8.android.ui.sponsorHub.watchAndRespond.AWatchAndRespondCongrats"
android:screenOrientation="portrait"
android:theme="#style/App8Theme.noActionBar"/>
And specify the same class at the top of the Activity's file:
package com.weare8.android.ui.sponsorHub.watchAndRespond
I then have a method called "initData" that is called in the Activity's onResume method. The app crashes when it is called with the following stack trace:
2021-03-09 13:35:30.362 25909-25909/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.eight.app.stg, PID: 25909
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/weare8/android/ui/sponsorHub/watchAndRespond/AWatchAndRespondCongrats$initData$1$1;
at com.weare8.android.ui.sponsorHub.watchAndRespond.AWatchAndRespondCongrats.initData(AWatchAndRespondCongrats.kt:71)
at com.weare8.android.ui.sponsorHub.watchAndRespond.AWatchAndRespondCongrats.onResume(AWatchAndRespondCongrats.kt:51)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1456)
at android.app.Activity.performResume(Activity.java:8135)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4428)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4470)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7660)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.weare8.android.ui.sponsorHub.watchAndRespond.AWatchAndRespondCongrats$initData$1$1" on path: DexPathList[[zip file "/data/app/~~VZbIKt-wdKVMzrVi50UpkQ==/com.eight.app.stg-NFHvGS3I4QjJpJmMcbLfLw==/base.apk"],nativeLibraryDirectories=[/data/app/~~VZbIKt-wdKVMzrVi50UpkQ==/com.eight.app.stg-NFHvGS3I4QjJpJmMcbLfLw==/lib/arm64, /data/app/~~VZbIKt-wdKVMzrVi50UpkQ==/com.eight.app.stg-NFHvGS3I4QjJpJmMcbLfLw==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.weare8.android.ui.sponsorHub.watchAndRespond.AWatchAndRespondCongrats.initData(AWatchAndRespondCongrats.kt:71)
at com.weare8.android.ui.sponsorHub.watchAndRespond.AWatchAndRespondCongrats.onResume(AWatchAndRespondCongrats.kt:51)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1456)
at android.app.Activity.performResume(Activity.java:8135)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4428)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4470)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7660)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Invalidate cache/Restart does not work, deleting the .idea folder does not work, Clean/rebuild project does not work. I've seen this error before but not for a specific method. I have no idea why this stopped working, seemingly spontaneously. What else can I try?
Edit: crashing method:
private fun initData(offer: WatchAndRespondOffer) = with (offer) {
Interactors.preferences.removedCachedOffer(offer.campaignId!!)
if (!offer.linkToProductOrDiscountIncentive?.shortInstruction.isNullOrEmpty()) {
offerTv.visibility = View.VISIBLE
offerTv.text = offer.linkToProductOrDiscountIncentive?.shortInstruction
}
val imageToBeDisplayed = if (!offer.ctaImageUri.isNullOrEmpty()) {
offer.ctaImageUri
} else {
offer.coverTileUri
}
if (cashIncentive != null && charityDonationIncentive != null) {
title_description.setText(R.string.watch_and_respond_congrats_description)
title_first.show()
title_second.show()
} else if (charityDonationIncentive != null) {
title_second.hide()
title_first.setText(R.string.watch_and_respond_congrats_title_charity)
title_description.setText(R.string.watch_and_respond_congrats_donation_description)
} else if (cashIncentive != null) {
title_second.hide()
title_first.setText(R.string.watch_and_respond_congrats_title_cash)
title_description.setText(R.string.watch_and_respond_congrats_description)
}
val isUnite = offer.isUniteIncentive?: false
if (isUnite){
title_first.hide()
title_second.hide()
title_description.hide()
wellDoneTv.show()
} else{
wellDoneTv.hide()
}
setupLinkIncentive(offer)
Glide.with(applicationContext).asBitmap().load(imageToBeDisplayed).into(object : SimpleTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
val width = Resources.getSystem().displayMetrics.widthPixels - 40
val widthRatio = resource.width
val heightRatio = resource.height.toFloat()
val height = ((width.toFloat() / widthRatio.toFloat()) * heightRatio).toInt()
tileIv.layoutParams.height = height
Glide.with(applicationContext).load(imageToBeDisplayed).apply(RequestOptions().override(width, height).skipMemoryCache(true)).into(tileIv)
}
})
}
Related
I am trying to make a app that can search the places with google autocomplete search in jetpack compose but when I launch the intent of the autocomplete and after writing one later app is crashing here is my code:-
My ViewModel
init {
if (!Places.isInitialized()) {
Places.initialize(context, "$API_KEY", Locale.US);
}
}
val field = listOf(Place.Field.NAME, Place.Field.LAT_LNG)
My UI
val context = LocalContext.current
val intent = Autocomplete.IntentBuilder(AutocompleteActivityMode.OVERLAY, viewModel.field).build(context)
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if(it.resultCode == 2){
val place = Autocomplete.getPlaceFromIntent(it.data)
val latLng = place.latLng
Log.d("place LatLng: ", latLng.toString())
// move the camera position of the map
// cameraPositionState.move(CameraUpdateFactory.newLatLngZoom(lonLat, 15f))
}
}
My Logcat
FATAL EXCEPTION: main Process: com.example.trip, PID: 19245
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=988884199, result=2, data=Intent { (has extras) }} to activity {com.example.trip/com.example.trip.MainActivity}: java.lang.IllegalArgumentException: Intent expected to contain a Place, but doesn't.
at android.app.ActivityThread.deliverResults(ActivityThread.java:5015)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5056)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.IllegalArgumentException: Intent expected to contain a Place, but doesn't.
at com.google.android.libraries.places.internal.zzha.zze(com.google.android.libraries.places:places##2.6.0:1)
at com.google.android.libraries.places.internal.zzfo.zzb(com.google.android.libraries.places:places##2.6.0:3)
at com.google.android.libraries.places.widget.Autocomplete.getPlaceFromIntent(com.google.android.libraries.places:places##2.6.0:1)
at com.example.trip.ui.theme.tripSection.createTrip.CreateTripScreenKt$CreateTripScreen$2$1$launcher$1.invoke(CreateTripScreen.kt:116)
at com.example.trip.ui.theme.tripSection.createTrip.CreateTripScreenKt$CreateTripScreen$2$1$launcher$1.invoke(CreateTripScreen.kt:113)
at androidx.activity.compose.ActivityResultRegistryKt$rememberLauncherForActivityResult$1$1.onActivityResult(ActivityResultRegistry.kt:105)
at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:392)
at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:351)
at androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.java:638)
at android.app.Activity.dispatchActivityResult(Activity.java:8310)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5008)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5056)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
My gradle
//Google places api
implementation 'com.google.android.libraries.places:places:2.6.0'
I'm trying to know when the animation close of the softkeyboard is done. So i try to use this function :
val rootLayout = findViewById<ConstraintLayout>(R.id.root_layout)
rootLayout.setWindowInsetsAnimationCallback(object : WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) {
override fun onProgress(insets: WindowInsets, runningAnimations: MutableList<WindowInsetsAnimation>): WindowInsets {
//TODO("Not yet implemented")
return insets
}
override fun onEnd(animation: WindowInsetsAnimation) {
super.onEnd(animation)
val showingKeyboard = rootLayout.rootWindowInsets.isVisible(WindowInsets.Type.ime())
if (!showingKeyboard) {
println("Keyboard is now closed")
}
}
})
but when i launch the app on my phone (and several emu) i have to face to this error :
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/WindowInsetsAnimation$Callback;
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1251)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3222)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3459)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2046)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:225)
at android.app.ActivityThread.main(ActivityThread.java:7564)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.WindowInsetsAnimation$Callback" on path: DexPathList[[zip file "/data/app/com.example.buginsetsanimationlistener-wRvK7cMTAxdBF1RCG19tlA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.buginsetsanimationlistener-wRvK7cMTAxdBF1RCG19tlA==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:230)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1251)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3222)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3459)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2046)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:225)
at android.app.ActivityThread.main(ActivityThread.java:7564)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
I don't understand what i should do, thanks for your answers !
I finally found my mystake. this method is for API 30+. But i've found another way to achieve my goal :
This is work when i close by myself the soft keyboard.
imm.hideSoftInputFromWindow(rootLayout.windowToken, 0, object : ResultReceiver(null) {
override fun onReceiveResult(resultCode: Int, resultData: Bundle?) {
if (resultCode == InputMethodManager.RESULT_UNCHANGED_HIDDEN ||
resultCode == InputMethodManager.RESULT_HIDDEN) {
//Soft has finished the animation
}
}
}
})
Hope this answer help someone :)
I tried to run the job, but I get one error all the time. code:
class UpdaterJob #Inject constructor(
private val context: Context,
workerParams: WorkerParameters
) :
CoroutineWorker(context, workerParams) {
override suspend fun doWork(): Result = //coroutineScope {
withContext(Dispatchers.IO) {
Result.success()
// }
}
companion object {
const val TAG = "UpdateChecker"
fun setupTask(context: Context) {
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val request = PeriodicWorkRequestBuilder<UpdaterJob>(
1, TimeUnit.DAYS,
1, TimeUnit.HOURS
)
.addTag(TAG)
.setConstraints(constraints)
.build()
// WorkManager.getInstance(context).enqueue(request)
WorkManager.getInstance(context)
.enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, request)
}
fun cancelTask(context: Context) {
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
}
}
}
I tried to make my DaggerWorkerFactory, by Dagger2: Unable to inject dependencies in WorkManager , but I still get one and the same error, log:
2021-02-02 13:39:15.894 7542-7542/com.rulate.rulateapp.debug
E/AndroidRuntime: FATAL EXCEPTION: main Process:
com.rulate.rulateapp.debug, PID: 7542 java.lang.NoClassDefFoundError:
Failed resolution of:
Landroidx/work/impl/utils/futures/AbstractFuture;
at androidx.work.impl.WorkManagerImpl.initialize(WorkManagerImpl.java:181)
at androidx.work.WorkManager.initialize(WorkManager.java:210)
at com.rulater.rulateapp.ui.App.configureWorkManager(App.kt:60)
at com.rulater.rulateapp.ui.App.onCreate(App.kt:47)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.lang.ClassNotFoundException:
androidx.work.impl.utils.futures.AbstractFuture
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at androidx.work.impl.WorkManagerImpl.initialize(WorkManagerImpl.java:181)
at androidx.work.WorkManager.initialize(WorkManager.java:210)
at com.rulater.rulateapp.ui.App.configureWorkManager(App.kt:60)
at com.rulater.rulateapp.ui.App.onCreate(App.kt:47)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/google/common/util/concurrent/ListenableFuture;
at androidx.work.impl.WorkManagerImpl.initialize(WorkManagerImpl.java:181)
at androidx.work.WorkManager.initialize(WorkManager.java:210)
at com.rulater.rulateapp.ui.App.configureWorkManager(App.kt:60)
at com.rulater.rulateapp.ui.App.onCreate(App.kt:47)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.google.common.util.concurrent.ListenableFuture" on path:
DexPathList[[zip file
"/data/app/~~hUB4V6hTR0qg-4tdmVBeBg==/com.rulate.rulateapp.debug-qn72fwjfGyiwIXEoVyVyTw==/base.apk"],nativeLibraryDirectories=[/data/app/~~hUB4V6hTR0qg-4tdmVBeBg==/com.rulate.rulateapp.debug-qn72fwjfGyiwIXEoVyVyTw==/lib/x86,
/data/app/~~hUB4V6hTR0qg-4tdmVBeBg==/com.rulate.rulateapp.debug-qn72fwjfGyiwIXEoVyVyTw==/base.apk!/lib/x86,
/system/lib, /system_ext/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at androidx.work.impl.WorkManagerImpl.initialize(WorkManagerImpl.java:181)
at androidx.work.WorkManager.initialize(WorkManager.java:210)
at com.rulater.rulateapp.ui.App.configureWorkManager(App.kt:60)
at com.rulater.rulateapp.ui.App.onCreate(App.kt:47)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Have you tried explicitly adding guava to your build.gradle dependencies:
implementation 'com.google.guava:guava:28.2-android'
using OkHTTP I am trying to retrieve a text file and put hat into the textView on the main activity,
Gradle will say build successful but the emulator app will just crash on launch and provide this error.
I have added the correct permissions in the AndroidManifest.xml and the correct implementation in the gradle build
package com.example.vectortestapi
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import okhttp3.*
import java.io.IOException
abstract class MainActivity : AppCompatActivity() {
private val mTextView: TextView = findViewById<TextView>(R.id.resultText);
private val client = OkHttpClient()
private val url = "https://publicobject.com/helloworld.txt"
private val request: Request = Request.Builder()
.url(url)
.build();
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
getAPI();
}
private fun getAPI(){
client.newCall(request).enqueue(object: Callback {
override fun onFailure(call: Call, e: IOException) {
e.printStackTrace()
}
override fun onResponse(call: Call, response: Response) {
val inputStream = response.body?.string()
runOnUiThread{
mTextView.text = inputStream
}
}
})
}
}
produces this error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.vectortestapi, PID: 9900
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.vectortestapi/com.example.vectortestapi.MainActivity}: java.lang.InstantiationException: java.lang.Class<com.example.vectortestapi.MainActivity> cannot be instantiated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3365)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.InstantiationException: java.lang.Class<com.example.vectortestapi.MainActivity> cannot be instantiated
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1253)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3353)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
I/Process: Sending signal. PID: 9900 SIG: 9
Abstract classes cannot be instantiated, but they can be subclassed.
I want to predict hand written words using pre-trained model which is trained using CNN and RNN Combination. offline handwritten words recognizer without using server.
public void pickImage(View view) {
bitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.img1);
img.setImageBitmap(bitmap);
Toast.makeText(getApplicationContext(),"Width:- "+bitmap.getWidth()+" Height "+bitmap.getHeight(),Toast.LENGTH_SHORT).show();
convertBitmapToByte();
}
private void convertBitmapToByte()
{
if (mdata == null)
{
Toast.makeText(getApplicationContext(),"Return",Toast.LENGTH_SHORT).show();
return;
}
mdata.rewind();
bitmap.getPixels(getPixels,0,bitmap.getWidth(),0,0,bitmap.getWidth(),bitmap.getHeight());
int pixel =0;
for(int i=0;i<748;++i)
{
for(int j=0;j<294;++j)
{
final int val = getPixels[pixel++];
mdata.putFloat(convertToGreyScale(val));
}
}
}
private float convertToGreyScale(int colour)
{
return (((colour >> 16) & 0xFF)+((colour >>8) & 0xFF)+((colour & 0xFF)))/3.0f/255.0f;
}
public void predAndSet(View view) {
tv.setText("Temp");
if(mdata == null)
{
Toast.makeText(getApplicationContext(),"Return",Toast.LENGTH_SHORT).show();
return;
}
interpreter.run(mdata,mResult);
tv.setText(Arrays.toString(mResult[0]));
}
}
Stacktrace
Process: com.soham.s.charrecongizer, PID: 29211
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6669)
at android.view.View.performClickInternal(View.java:6638)
at android.view.View.access$3100(View.java:789)
at android.view.View$PerformClick.run(View.java:26145)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6863)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6669)
at android.view.View.performClickInternal(View.java:6638)
at android.view.View.access$3100(View.java:789)
at android.view.View$PerformClick.run(View.java:26145)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6863)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.tensorflow.lite.Interpreter.run(java.lang.Object, java.lang.Object)' on a null object reference
at com.soham.s.charrecongizer.MainActivity.predAndSet(MainActivity.java:103)
I want to see the text in the image to be predicted and to be shown in a textbox