Android - Crashing on setContentView() prior to v24 API - android

When I run my app on the emulator with version 27 & 28 APIs, everything works for me. However, as soon as I try to go to a lower level API, I get error messages regarding the setContentView() method in my custom Activity.java class.
Here is the stack trace:
2018-12-06 15:37:59.166 9426-9426/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mplexvr.ribbonracker, PID: 9426
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mplexvr.ribbonracker/com.mplexvr.ribbonracker.RibbonRackerActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f0b0000
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0b0000
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
at android.content.res.Resources.getDrawable(Resources.java:766)
at android.content.Context.getDrawable(Context.java:525)
at com.android.internal.widget.ToolbarWidgetWrapper.setIcon(ToolbarWidgetWrapper.java:322)
at com.android.internal.widget.ActionBarOverlayLayout.setIcon(ActionBarOverlayLayout.java:737)
at com.android.internal.policy.PhoneWindow.setDefaultIcon(PhoneWindow.java:1737)
at android.app.Activity.initWindowDecorActionBar(Activity.java:2400)
at android.app.Activity.setContentView(Activity.java:2415)
at com.mplexvr.ribbonracker.RibbonRackerActivity.onCreate(RibbonRackerActivity.java:46)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
I tried to run this app on both a phone and emulator with a version 24 api, and nothing works. My activity_main.xml that the onCreate() method tries to call just contains two fragments that are modified in the onCreate() method. Here is a snippet of code from that:
/* This code runs perfectly fine on the version 28 and 27 api on the emulator*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
images = new ArrayList<>();
imageNames = new ArrayList<>();
setContentView(R.layout.activity_main);
Log.v(TAG, "I got in onCreate");
//Create the fragment for the ranking and add it to the current view
// Get references to the TitleFragment and to the QuotesFragment containers
mRibbonFrameLayout = findViewById(R.id.ribbon_fragment_container);
mChecklistFrameLayout = findViewById(R.id.checkbox_fragment_container);
...
}
I tried looking this problem up, but nothing I found has solved this problem - at least publicly.
UPDATE Solved within 5 minutes when I figured out that a folder had a version of 26, which would limit on using that version.

Related

Upgraded to android studio 4, now reports that main activity 'is not accessible from class android.app.Instrumentation'

This happens every time I upgrade, usually for different reasons:
I just upgraded to Android Studio 4, I'm targeting android 5/Api21 upwards.
This time my activity crashes on start up with claiming that my main activity 'is not accessible from class android.app.Instrumentation'
I'm not sure what 'android.app.Instrumentation' is or whether there's some requirement in my code, a dependency or android studio that's requiring it. My main class is public so it should be able to see it.
My class declaration looks like this:
public class AnthracitePlayer extends AppCompatActivity
and AppCompatActivity, which I believe is something I used to remove the title bar is declared like this:
public class AppCompatActivity extends FragmentActivity implements AppCompatCallback,
TaskStackBuilder.SupportParentable, ActionBarDrawerToggle.DelegateProvider {
and my create method starts like this:
Override
public void onCreate(Bundle savedInstanceState)
{
Log.d(TAG,"Entered onCreate");
super.onCreate(savedInstanceState);
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
String displayName = display.getName();
I'm not sure if any of those is upsetting this instrumentation thing.
The error follows:
07-12 14:32:26.251 20528-20528/totga.anthraciteplayerapi21 D/ResourcesManager: creating new AssetManager and set to /data/app/totga.anthraciteplayerapi21-2/base.apk
07-12 14:32:26.341 20528-20528/totga.anthraciteplayerapi21 D/AndroidRuntime: Shutting down VM
07-12 14:32:26.341 20528-20528/totga.anthraciteplayerapi21 E/AndroidRuntime: FATAL EXCEPTION: main
Process: totga.anthraciteplayerapi21, PID: 20528
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{totga.anthraciteplayerapi21/totga.anthraciteplayerapi21.AnthracitePlayer}: java.lang.IllegalAccessException: totga.anthraciteplayerapi21.AnthracitePlayer() is not accessible from class android.app.Instrumentation
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2515)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
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:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.IllegalAccessException: totga.anthraciteplayerapi21.AnthracitePlayer() is not accessible from class android.app.Instrumentation
at java.lang.Class.newInstance(Class.java:1647)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2505)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) 
at android.app.ActivityThread.access$900(ActivityThread.java:172) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:5832) 
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:1399) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
I managed to get this to run (although I have new problems now) by changing onCreate from 'public' to 'protected'.
What I think happened is that either the permissions in the parent class inside the android library changed or the rules governing access levels became more strict - public should have worked either way.

Running android app problem : E/AndroidRuntime: FATAL EXCEPTION: main

I get the next message from logcat afyter trying to run my app in andorid studio:
5545-5545/com.example.reyesdelafter E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.reyesdelafter, PID: 5545
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.reyesdelafter/com.example.reyesdelafter.MainActivity}: java.lang.InstantiationException: java.lang.Class cannot be instantiated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.InstantiationException: java.lang.Class cannot be instantiated
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
Also y get the message: "E/art: Failed sending reply to debugger: Broken pipe" before that, my code is exactly the same as in the beginning (and it runned well in the emulator, but I do some tries to change the icons of bottom nav view, and some other things but I get back everything to normality (or so I thought ) and it does not run properly. What is the possible problem ? I alredy tried to uprgrade SDK tools, and make sure my Manifest.xml includes my main activity.
The app has just the splash screen and login with Firebase alredy well done and it runned well before that. Thanks

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.appmediocurso, PID: 2740

I'm trying to insert values to the database on SQLite by SQLiteOpenHelper bur the app closes.
I'm working with SQLiteOpenHelper on Android studio, and using an activity to insert values in the database, when I first enter to the activity I can insert all the values I want, but when I go out, re-enter the activity and press the button "Registar" that insert the values on the table, the app closes without showing the Toast message.
public void Registrar (View view){
Toast.makeText(this,"Entro al registrar",Toast.LENGTH_SHORT).show();
AdminSQLiteOpenHelper admin = new AdminSQLiteOpenHelper(this, "administracion", null, 1);
SQLiteDatabase bd = admin.getWritableDatabase(); <- in this line close
'''''
'''''
}
THE LOG MODULE
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.appmediocurso, PID: 2740
java.lang.IllegalStateException: Could not execute method for android:onClick
at $DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6205)
at android.widget.TextView.performClick(TextView.java:11103)
at android.view.View$PerformClick.run(View.java:23653)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
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:6205) 
at android.widget.TextView.performClick(TextView.java:11103) 
at android.view.View$PerformClick.run(View.java:23653) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: android.database.sqlite.SQLiteException: Can't downgrade database from version 5 to 1
at android.database.sqlite.SQLiteOpenHelper.onDowngrade(SQLiteOpenHelper.java:360)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:254)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at com.example.appmediocurso.NuevoDeudor.Registrar(NuevoDeudor.java:57)
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:6205) 
at android.widget.TextView.performClick(TextView.java:11103) 
at android.view.View$PerformClick.run(View.java:23653) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
E/Watchdog: !#Sync 4269 [26_abr_16_41_35.985]
E/wifi: failed to get channel list : -95
I only expect to insert the values even if it's the second ot third time I enter to the actitity.
The cause is that before the failed run the database had had it's version number set at 5 but you are now trying to use version 1 without overriding the SQliteOpenHelper's onDowngrade method; which without being overridden results in the encountered exception, as is intended, as reducing the version number is generally not done.
That is AdminSQLiteOpenHelper admin = new AdminSQLiteOpenHelper(this, "administracion", null, 5); was used but now AdminSQLiteOpenHelper admin = new AdminSQLiteOpenHelper(this, "administracion", null, 1); has been used (4th parameter was 5 but is now 1) .
You could fix this by again using 5 as the version number.
Another fix could be to uninstall the App or delete the App's data and then rerun the App without changing the version. Noting that this would result in all data being lost.
Yet another fix could be to override the onUpgrade method (perhaps doing nothing), the version should then be set to 1, the data would be kept.
There are other ways of fixing this issue but they would be a little more complicated and offer no advantage over the mentioned fixes.

Android Studio: Problems with WebView.onCreateInputConnection

I wrote a webview application for some Android 4.2 device with a custom inapp keyboard. In fact, the app runs without any error on devices with Android 4.2.
I know this is a very old android version, this is reason why I got now a new device with Android 7.1.2, but unfortunately, the app doesn't work on this device.
In the following code example I create an InputConnection to the WebView and assume that reference to my custom keyboard.
This is the code who turns into an error:
val ic = mWebView.onCreateInputConnection(EditorInfo())
mMyKeyboard.setInputConnection(ic)
Code of "setInputConnection" of object "MyKeyboard"
fun setInputConnection(ic: InputConnection) {
inputConnection = ic
}
error message:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.aaa.bbb, PID: 5012
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aaa.bbb/com.example.aaa.bbb.MainActivity}: java.lang.IllegalStateException: ic must not be null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.IllegalStateException: ic must not be null
at com.example.huf.ifsscan.MainActivity.onCreate(MainActivity.kt:59)
at android.app.Activity.performCreate(Activity.java:6723)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6123) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 
E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY)
Currently I have no idea why this happens.
The documentation for "onCreateInputConnection" of WebView object show it should be fine.
Android Developers | Webview
There is no different if I compile it under API 19 (Android 4.2) or API 25 (7.1).
Does anyone have any idea what the problems might be?
Thanks in advance
It seems like I found the problem.
In the app for Android 4.2 the above code of getting and assuming the inputConnection was part of the "onCreate" function. It semms like Android 7.1 works there a little bit different, after I moved the specified code part to "onPageFinished" function, it works fine.
I guess there is a reference missing in the onCreate function. But I find it odd that it worked before.

NullPointer while using Zebra Library in yet existing project

Actually i'm trying to implement zebra EMDK library to my yet existing project.
I've followed step by step the following guide and in a new project all worked perfectly but when i've tryed to use the library in my project i've got the following error:
2019-03-13 15:24:55.720 4671-4678/it.gabtamagnini.realco E/art: Failed sending reply to debugger: Broken pipe
2019-03-13 15:25:01.239 4671-4671/it.gabtamagnini.realco E/AndroidRuntime: FATAL EXCEPTION: main
Process: it.gabtamagnini.realco, PID: 4671
java.lang.RuntimeException: Unable to start activity ComponentInfo{it.gabtamagnini.realco/it.gabtamagnini.realco.InventarioActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contentEquals(java.lang.CharSequence)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contentEquals(java.lang.CharSequence)' on a null object reference
at it.gabtamagnini.realco.InventarioActivity.handleDecodeData(InventarioActivity.java:1160)
at it.gabtamagnini.realco.InventarioActivity.onCreate(InventarioActivity.java:129)
at android.app.Activity.performCreate(Activity.java:6723)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6123) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 
Code where i get the null pointer:
private void handleDecodeData(Intent i) {
//Check the intent action is for us
if (i.getAction().contentEquals("com.symbol.emdksample.RECVR")) {
//Get the source of the data
String source = i.getStringExtra("com.motorolasolutions.emdk.datawedge.source");
//Check if the data has come from the Barcode scanner
if (source.equalsIgnoreCase("scanner")) {
//Get the data from the intent
String data = i.getStringExtra("com.motorolasolutions.emdk.datawedge.data_string");
//Check that we have received data
if(data != null && data.length() > 0)
{
Toast.makeText(InventarioActivity.this,data,Toast.LENGTH_LONG).show();
}
}
}
}
that tutorial is quite old - Data Capture Profiles were recently deprecated. If you are trying this on a newer device then I suspect the com.motorolasolutions... Intents have been removed as the string extra has been 'com.symbol.datawedge.data_string for quite some time. I suggest reading https://developer.zebra.com/community/home/blog/2018/06/03/moving-from-the-emdk-data-capture-profile-to-datawedge which explains what has happened to the Data Capture profile but if you are looking for a known working sample then http://www.darryncampbell.co.uk/2017/12/13/tutorial-scan-with-datawedge-intent-output-on-zebra-devices/ should be a good starting point.
For clarity, I work for Zebra

Categories

Resources