Instant crash with the use of a custom view - android

I never used custom view before, so most likely I am doing something wrong.
Below is my Java code for my SmartTabLayout class that supposed to switch between MODE_FIXED and MODE_SCROLLABLE based on total combined width of all its tabs.
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
public class SmartTabLayout extends android.support.design.widget.TabLayout {
public SmartTabLayout(Context context) {
super(context);
}
public SmartTabLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SmartTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (getTabCount() == 0) return;
try {
ViewGroup tabLayout = (ViewGroup)getChildAt(0);
int combinedWidth = 0;
for (int i = 0; i < tabLayout.getChildCount(); i++)
combinedWidth += tabLayout.getChildAt(i).getMeasuredWidth();
setTabMode(combinedWidth <= getMeasuredWidth() ? MODE_FIXED : MODE_SCROLLABLE);
} catch (Exception e) {
// e.printStackTrace();
}
}
}
My layout XML file contains the following part:
<SmartTabLayout
android:id="#+id/tabLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="scrollable"
android:layout_gravity="center_horizontal">
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Center" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Right" />
</SmartTabLayout>
When (in my XML file) I change SmartTabLayout to android.support.design.widget.TabLayout, all works normal, but with no "smart" feature that is desired. So I assume the XML code is fine. But when I use my SmartTabLayout in the XML file, the app crashes right after launch. Debugger doesn't even call a single line of my custom code. What am I missing?
Logs (below) includes the following message:
Didn't find class "android.view.SmartTabLayout" on path...
Should I somewhere explicitly point to my custom view class?
02-16 15:56:14.328 24316-24316/? E/Zygote: v2
02-16 15:56:14.328 24316-24316/? I/libpersona: KNOX_SDCARD checking this for 10327
02-16 15:56:14.328 24316-24316/? I/libpersona: KNOX_SDCARD not a persona
02-16 15:56:14.330 24316-24316/? E/Zygote: accessInfo : 0
02-16 15:56:14.331 24316-24316/? W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[2], Con:u:r:zygote:s0 SPD:SEPF_SECMOBILE_7.0_0006 RAM:SEPF_SECMOBILE_7.0_0010, [-1 -1 -9 -1 0 1]
02-16 15:56:14.332 24316-24316/? I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=com.example.android
02-16 15:56:14.339 24316-24316/? I/art: Late-enabling -Xcheck:jni
02-16 15:56:14.381 24316-24316/? D/TimaKeyStoreProvider: TimaSignature is unavailable
02-16 15:56:14.381 24316-24316/? D/ActivityThread: Added TimaKeyStore provider
02-16 15:56:14.406 24316-24316/com.example.android W/ActivityThread: Application com.example.android is waiting for the debugger on port 8100...
02-16 15:56:14.409 24316-24316/com.example.android I/System.out: Sending WAIT chunk
02-16 15:56:15.420 24316-24323/com.example.android I/art: Debugger is active
02-16 15:56:15.611 24316-24316/com.example.android I/System.out: Debugger has connected
02-16 15:56:15.611 24316-24316/com.example.android I/System.out: waiting for debugger to settle...
02-16 15:56:15.811 24316-24316/com.example.android I/System.out: waiting for debugger to settle...
02-16 15:56:16.012 24316-24316/com.example.android I/System.out: waiting for debugger to settle...
02-16 15:56:16.212 24316-24316/com.example.android I/System.out: waiting for debugger to settle...
02-16 15:56:16.412 24316-24316/com.example.android I/System.out: waiting for debugger to settle...
02-16 15:56:16.613 24316-24316/com.example.android I/System.out: waiting for debugger to settle...
02-16 15:56:16.813 24316-24316/com.example.android I/System.out: waiting for debugger to settle...
02-16 15:56:17.013 24316-24316/com.example.android I/System.out: debugger has settled (1370)
02-16 15:56:17.112 24316-24316/com.example.android W/System: ClassLoader referenced unknown path: /data/app/com.example.android-2/lib/arm64
02-16 15:56:17.129 24316-24316/com.example.android D/ContextRelationMgrBrdg: loadKlass() : caller=com.samsung.android.bridge.multiscreen.common.ContextRelationManagerBridge.<clinit>:28 com.samsung.android.bridge.multiscreen.common.ContextRelationManagerBridge.getInstance:-1
02-16 15:56:17.139 24316-24316/com.example.android I/InstantRun: starting instant run server: is main process
02-16 15:56:17.210 24316-24316/com.example.android W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
02-16 15:56:17.315 24316-24316/com.example.android D/TextView: setTypeface with style : 0
02-16 15:56:17.316 24316-24316/com.example.android D/TextView: setTypeface with style : 0
02-16 15:56:17.348 24316-24316/com.example.android D/AndroidRuntime: Shutting down VM
02-16 15:56:17.354 24316-24316/com.example.android E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android, PID: 24316
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android/com.example.android.Main}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class SmartTabLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class SmartTabLayout
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class SmartTabLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.SmartTabLayout" on path: DexPathList[[zip file "/data/app/com.example.android-2/base.apk", zip file "/data/app/com.example.android-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.android-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.android-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.android-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.android-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.android-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.android-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.android-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.android-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.android-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.android-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.android-2/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:616)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:707)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:724)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:792)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.inflate(LayoutInflater.java:525)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:378)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.android.Main.onCreate(Main.java:52)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2900)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)02-16 15:56:17.355 24316-24316/com.example.android E/AndroidRuntime:
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

The logs point to an
java.lang.ClassNotFoundException: Didn't find class "android.view.SmartTabLayout"
Error, Try changing your layout to
<<package_name>.SmartTabLayout
android:id="#+id/tabLayout"
.../>

As many of us thought, change of <SmartTabLayout> to <com.example.android.SmartTabLayout> would make a trick.
But it wasn't enough to make it work. I had to add:
package com.example.android;
at the beginning of my SmartTabLayout class file. Now it works, but it shows a warning
Package name 'com.example.android' does not correspond to the file
path ''
So I have to move my Java class source code from ...\java directory to ...\java\com.example.android folder and now it works without warnings.
That move of file makes sense, because I had added package com.example.android;.
But why I had to make this custom view a part of my package to make it work? Shouldn't that work even outside of the package? Weird. But as I wrote, this is/was my first experience with the custom view, so I have learned something.
Hopefully it will help others who experience same issue.

Try to make the following changes for the super calls for the first two constructors to be like this:
public SmartTabLayout(Context context) {
super(context, null);
}
public SmartTabLayout(Context context, AttributeSet attrs) {
super(context, attrs, 0);
}
public SmartTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

Related

I wrote an apk but it shows me unfortunately stopped working

What I see in "Run" footer. It's just a simple UI design and gets installed successfully,
but when I try to open it, it crashes and says " unfortunately stopped working".
I'm kind of new to Android Studio.
also signed the apk but no differences.
02/23 17:05:26: Launching app
$ adb push C:\Users\The King Gh0$T\AndroidStudioProjects\MOCBioPrinter\app\build\outputs\apk\debug\app-debug.apk /data/local/tmp/mking.mocbioprinter
$ adb shell pm install -t -r "/data/local/tmp/mking.mocbioprinter"
pkg: /data/local/tmp/mking.mocbioprinter
Success
APK installed in 3 s 878 ms
$ adb shell am start -n "mking.mocbioprinter/mking.mocbioprinter.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Connected to process 8148 on device samsung-sm_t561-3801b1493e30a200
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
D/dalvikvm: Late-enabling CheckJNI
D/dalvikvm: Debugger has detached; object registry had 1 entries
D/ActivityThread: handleBindApplication:mking.mocbioprinter
W/dalvikvm: Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lmking/mocbioprinter/MainActivity;
Class init failed in newInstance call (Lmking/mocbioprinter/MainActivity;)
D/AndroidRuntime: Shutting down VM
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4171dbc0)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: mking.mocbioprinter, PID: 8148
java.lang.UnsatisfiedLinkError: Couldn't load native-lib from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/mking.mocbioprinter-7.apk"],nativeLibraryDirectories=[/data/app-lib/mking.mocbioprinter-7, /vendor/lib, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at mking.mocbioprinter.MainActivity.<clinit>(MainActivity.java:29)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
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:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
I/Process: Sending signal. PID: 8148 SIG: 9
Application terminated.

My app crashes when I try to implement a Scroll Bar

I have a problem with my app, i started coding in Android studio recently and i got a problem i can`t solve.
So i have a main page with 4 activities, when i run the program in the emulator the app opens and 3 of the activities work perfectly but the one where i try to implement the scrollbar crashes when i click to open the activity.
Here's the code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
tools:context=".coffeeGrowth" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:keepScreenOn="true"
android:text="#string/large_text"
android:textColor="#008000"
android:textSize="30sp"
android:textStyle="italic" />
</RelativeLayout>
</ScrollView>
And the crash:
07/03 16:54:21: Launching app $ adb install-multiple -r -t -p
com.example.android.coffeeknowledge C:\Users\Daud
Jawad\CoffeeKnowledge\app\build\intermediates\instant-run-apk\debug\app-debug.apk
Split APKs installed $ adb shell am start -n
"com.example.android.coffeeknowledge/com.example.android.coffeeknowledge.MainActivity"
-a android.intent.action.MAIN -c android.intent.category.LAUNCHER Client not ready yet..Waiting for process to come online Connected to
process 10196 on device emulator-5554 Capturing and displaying logcat
messages from application. This behavior can be disabled in the
"Logcat output" section of the "Debugger" settings page. D/:
HostConnection::get() New Host Connection established 0x8aa1c1c0, tid
10196 D/: HostConnection::get() New Host Connection established
0x8aa1c540, tid 10218 I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1 W/OpenGLRenderer: Failed to choose
config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0 D/EGL_emulation: eglCreateContext:
0x8a9fe920: maj 2 min 0 rcv 2 D/EGL_emulation: eglMakeCurrent:
0x8a9fe920: ver 2 0 (tinfo 0x99d98910) W/art: Before Android 4.1,
method int
android.support.v7.widget.DropDownListView.lookForSelectablePosition(int,
boolean) would have incorrectly overridden the package-private method
in android.widget.ListView D/EGL_emulation: eglMakeCurrent:
0x8a9fe920: ver 2 0 (tinfo 0x99d98910) D/AndroidRuntime: Shutting down
VM E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.coffeeknowledge, PID: 10196
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.coffeeknowledge/com.example.android.coffeeknowledge.coffeeGrowth}:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.view.View.setOnClickListener(android.view.View$OnClickListener)'
on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
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.NullPointerException: Attempt to invoke virtual method 'void
android.view.View.setOnClickListener(android.view.View$OnClickListener)'
on a null object reference
at com.example.android.coffeeknowledge.coffeeGrowth.onCreate(coffeeGrowth.java:98)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
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) 
Application terminated.
Thank you,
Daud.
Your XML is wrong my friend.
A ScrollView is not a layout option. Its a view. So you need to wrap your Layout around the scrollview. Keep in mind, a ScrollView can only have ONE child.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingTop="5dp" tools:context=".coffeeGrowth" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:keepScreenOn="true"
android:text="#string/large_text"
android:textColor="#008000"
android:textSize="30sp"
android:textStyle="italic" />
</ScrollView>
</RelativeLayout>

ConstraintLayout 1.0.2 shows nothing

I'm still having this weird problem. ConstraintLayout only works when it's on 'alpha-7', when I change it to '1.0.2' the latest version it shows nothing
Desired layout should look like this:
However, I'm getting this: "on a real HTC one M9 - CM 12.1.1"
** 'Show layout bounds' is On just so you can see that there are nothing on drawn on the device.
** I also tried with 'Show layout update' and it shows nothing as well
In the Layout Inspector the Username field, Password field and Login Button and showing:
XML layout:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragment_login"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/login_background"
android:clickable="true"
tools:context=".ui.login_sing_up.LoginFragment">
<android.support.design.widget.TextInputLayout
android:id="#+id/login_username_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="250dp"
android:textColorHint="#color/Azure"
android:visibility="visible"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.TextInputEditText
android:id="#+id/login_username"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_weight="1"
android:hint="#string/Username_or_Email"
android:inputType="textNoSuggestions|textEmailAddress"
android:lines="1"
android:linksClickable="false"
android:textColor="#color/Azure"
android:textColorHighlight="#color/black"
android:textColorHint="#color/Azure"
android:visibility="visible" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/login_password_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColorHint="#color/Azure"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/login_username_container"
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="#+id/login_password"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_weight="1"
android:hint="#string/password"
android:inputType="textPassword"
android:lines="1"
android:linksClickable="false"
android:textColor="#color/Azure"
android:textColorHighlight="#color/black"
android:textColorHint="#color/Azure" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/login_login"
style="#style/Base.Widget.AppCompat.Button.Colored.login"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:text="#string/login"
app:layout_constraintLeft_toLeftOf="#+id/login_password_container"
app:layout_constraintRight_toRightOf="#+id/login_password_container"
app:layout_constraintTop_toBottomOf="#+id/login_password_container" />
</android.support.constraint.ConstraintLayout>
LogCat shows nothing
07-20 20:00:01.028 7144-7144/? I/art: Late-enabling -Xcheck:jni
07-20 20:00:01.083 7144-7158/? E/art: Failed sending reply to debugger: Broken pipe
07-20 20:00:01.084 7144-7158/? I/art: Debugger is no longer active
07-20 20:00:03.344 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx I/LoadedApk: No resource references to update in package common
07-20 20:00:03.344 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx I/LoadedApk: No resource references to update in package com.brit.swiftdark
07-20 20:00:03.346 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx I/InstantRun: starting instant run server: is main process
07-20 20:00:03.473 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx W/ResourceType: For resource 0x01030224, entry index(548) is beyond type entryCount(29)
07-20 20:00:03.473 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx W/ResourceType: For resource 0x01030224, entry index(548) is beyond type entryCount(29)
07-20 20:00:03.511 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-20 20:00:03.614 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/DispatcherActivity: there is no user
07-20 20:00:03.621 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/UserCoordinator: making new Instance
07-20 20:00:03.652 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/DispatcherActivity: checking if there is user in Pref
07-20 20:00:03.653 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/DispatcherActivity: there is no user in Pref
07-20 20:00:03.653 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/DispatcherActivity: there is no user
07-20 20:00:03.658 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/DispatcherActivity: createFragment-LoginFragment
07-20 20:00:03.856 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/LoginFragment: creating ver
07-20 20:00:03.856 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/LoginFragment: done creating ver
07-20 20:00:03.861 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/DispatcherActivity: onResume
07-20 20:00:03.861 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/DispatcherActivity: onResume - null == mUC
07-20 20:00:03.861 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/UserCoordinator: got Instance from preferences
07-20 20:00:03.862 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/UserCoordinator: get userCoordinator
07-20 20:00:03.873 7144-7249/xxxxxxxxxxx.xxxxxxxxxxxxx D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
07-20 20:00:03.877 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx D/Atlas: Validating map...
07-20 20:00:03.878 7144-7169/xxxxxxxxxxx.xxxxxxxxxxxxx W/Binder: Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException: Attempt to read from field 'android.view.HardwareRenderer android.view.View$AttachInfo.mHardwareRenderer' on a null object reference
at android.view.WindowManagerGlobal.dumpGfxInfo(WindowManagerGlobal.java:476)
at android.app.ActivityThread$ApplicationThread.dumpGfxInfo(ActivityThread.java:1089)
at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:546)
at android.os.Binder.execTransact(Binder.java:446)
07-20 20:00:03.944 7144-7249/xxxxxxxxxxx.xxxxxxxxxxxxx I/Adreno: QUALCOMM build : 065751b,
Build Date : 04/15/15
OpenGL ES Shader Compiler Version: E031.25.03.07
Local Branch :
Remote Branch : quic/LA.BF64.1.2.1_rb2.9
Remote Branch : NONE
Reconstruct Branch : AU_LINUX_ANDROID_LA.BF64.1.2.1_RB2.05.01.00.081.016 + 065751b + NOTHING
07-20 20:00:03.967 7144-7249/xxxxxxxxxxx.xxxxxxxxxxxxx I/OpenGLRenderer: Initialized EGL, version 1.4
07-20 20:00:03.989 7144-7249/xxxxxxxxxxx.xxxxxxxxxxxxx D/OpenGLRenderer: Enabling debug mode 0
07-20 20:00:04.121 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#3781b87d time:768477070
07-20 20:00:04.130 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
07-20 20:00:04.130 7144-7144/xxxxxxxxxxx.xxxxxxxxxxxxx E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
build.gradle
repositories {
jcenter();
}
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
Things I tried:
Invalidating and restarting Android studio.
Tried on an emulator.
Tried on a Huawei Device.
Tried on an HTC one M9 Device.
Rolling back to 'Alpha-7' works fine.
Please if you need any more details let me know in the comment
After a year of waiting for a real explanation of what is going on and what happened after 'Alpha-7', I "Kindaaa~"figured it out.
The Short Answer
Activities with ConstraintLayout will do fine. however if you are adding a fragment on top, then make sure to make the activity background transparent.

"Detected prob_lem with app native libraries" message on certain phones

Everytime I run the app, I get this error message. There is nothing in the app, it is just a basic Navigation drawer template you get in the studio. The message only appears on certain devices (I ran it on a Zenfone 2 with Lineage OS(7.1.1)). My SDK version is 25 and I'm running android studio 2.3.1.
The message says:
Detected problems with app native libraries (please consult log for details):
libavcodec.so: text relocations
libswresample.so: text relocations
Log:
04-08 21:53:06.321 6798-6798/? I/art: Late-enabling -Xcheck:jni
04-08 21:53:06.482 6798-6798/com.platformpetal.platformpetal W/System: ClassLoader referenced unknown path: /data/app/com.platformpetal.platformpetal-1/lib/x86
04-08 21:53:06.494 6798-6798/com.platformpetal.platformpetal I/InstantRun: starting instant run server: is main process
04-08 21:53:06.664 6798-6831/com.platformpetal.platformpetal I/OpenGLRenderer: Initialized EGL, version 1.4
04-08 21:53:06.664 6798-6831/com.platformpetal.platformpetal D/OpenGLRenderer: Swap behavior 1
04-08 21:53:06.665 6798-6831/com.platformpetal.platformpetal W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
04-08 21:53:06.665 6798-6831/com.platformpetal.platformpetal D/OpenGLRenderer: Swap behavior 0
04-08 21:53:08.704 6798-6798/com.platformpetal.platformpetal W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
04-08 21:53:09.158 6798-6798/com.platformpetal.platformpetal W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
04-08 21:53:09.598 6798-6798/com.platformpetal.platformpetal E/WindowManager: android.view.WindowLeaked: Activity com.platformpetal.platformpetal.SplashScreen has leaked window DecorView#aaf4c69[] that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:418)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:331)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
at android.app.Dialog.show(Dialog.java:322)
at android.app.AlertDialog$Builder.show(AlertDialog.java:1112)
at android.app.Activity.performStart(Activity.java:6718)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2628)
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:6126)
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
)
Here the error message is for the activity being terminated before the message closes. There is nothing I can find which can cause the issue.
P.S. Stack Overflow doesn't allow word problem in question, so I wrote prob_lem
P.P.S. I'm relatively new to android, so don't be harsh :)
This is documented in https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk => you need to bundle those .so files with your application, apparently.

Application onCreate() never called

For some reason my app won't call custom application classes onCreate() anymore. Yesterday everything was fine but today my app crashes when it tries to open a connection to Realm.
java.lang.IllegalStateException: Call 'Realm.init(Context)' before calling this method.
Since I do initialize Realm in my custom application classes onCreate() I tried inserting a breakpoint and logging out of the method. Nothing.
This question had a similiar problem
Custom Application class onCreate() never called
I have disabled instant run, cleaned, rebuilt and even restarted android studio but the problem persists. I even tried checking out a commit from three days ago, which was most certainly working, but the result is the same.
Custom application class
public class MyApplication extends Application
{
#Override
public void onCreate()
{
super.onCreate();
JodaTimeAndroid.init(this);
Realm.init(this);
//more Realm initialization code
}
}
Manifest's application section
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="#style/MyTheme">
Any ideas what might cause this and how to get it fixed?
EDIT
Everything logcat puts out before crash
03-19 21:06:10.687 21869-21869/? E/Zygote: v2
03-19 21:06:10.687 21869-21869/? I/libpersona: KNOX_SDCARD checking this for 10323
03-19 21:06:10.687 21869-21869/? I/libpersona: KNOX_SDCARD not a persona
03-19 21:06:10.688 21869-21869/? E/Zygote: accessInfo : 0
03-19 21:06:10.688 21869-21869/? W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[2], Con:u:r:zygote:s0 RAM:SEPF_SECMOBILE_7.0_0004, [-1 -1 -1 -1 0 1]
03-19 21:06:10.689 21869-21869/? I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=hailer.com.hailer
03-19 21:06:10.692 21869-21869/? I/art: Late-enabling -Xcheck:jni
03-19 21:06:10.709 21869-21869/? D/TimaKeyStoreProvider: TimaSignature is unavailable
03-19 21:06:10.709 21869-21869/? D/ActivityThread: Added TimaKeyStore provider
03-19 21:06:10.790 21869-21869/hailer.com.hailer D/ContextRelationMgrBrdg: loadKlass() : caller=com.samsung.android.bridge.multiscreen.common.ContextRelationManagerBridge.<clinit>:28 android.app.LoadedApk.makeApplication:833
03-19 21:06:10.814 21869-21869/hailer.com.hailer W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
03-19 21:06:10.872 21869-21869/hailer.com.hailer D/AndroidRuntime: Shutting down VM
03-19 21:06:10.873 21869-21869/hailer.com.hailer E/AndroidRuntime: FATAL EXCEPTION: main
Process: hailer.com.hailer, PID: 21869
java.lang.RuntimeException: Unable to start activity ComponentInfo{hailer.com.hailer/hailer.com.hailer.activities.MainActivity}: java.lang.IllegalStateException: Call `Realm.init(Context)` before calling this method.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.IllegalStateException: Call `Realm.init(Context)` before calling this method.
at io.realm.Realm.getDefaultInstance(Realm.java:208)
at hailer.com.hailer.adapters.DiscussionAdapter.<init>(DiscussionAdapter.java:57)
at hailer.com.hailer.fragments.ChatListFragment.onCreateView(ChatListFragment.java:60)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2189)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:757)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2355)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2146)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2098)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2008)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
at hailer.com.hailer.activities.MainActivity.onStart(MainActivity.java:320)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1256)
at android.app.Activity.performStart(Activity.java:6929)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6688) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 
UPDATE
I trimmed down the libraries and disabled multidexing. Didn't help. I also went trough the DiscussionAdapter and ChatListFragment and both are fine. Realm is used in a correct manner and has worked for over a year without issues. I also have log.d("CUSTOMAPPCLS","onCreate called") in my custom application class which does not show in the log. Nor does a breakpoint stop in any part of the onCreate() call.
Now I got a new error. This time it's from PrefsAccessor - a wrapper for SharedPreferences which is also intialised in the custom applications onCreate call. PrefAccessor.init(this); I ran the build again but got the Realm error... The one considering PrefAccessor threw a nullpointer execption when trying to access the SharedPreferences. This further points to the fact that the application onCreate isn't called.
public static string isUseEnterToSendEnabled()
{
SharedPreferences prefs = applicationContext.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);// <-- nullpointer exception: Trying to call .getSharedPreferences on a null object
return prefs.getBoolean(ENTER_TO_SEND, false);
}
I found similar scenario to yours here:
https://github.com/realm/realm-java/issues/1800
The issue seems to be about having lots of libraries included to your project (such as Google Play Services) which might led to your app hitting the 65K methods limit.
Did you include any new dependencies to your project?
UPDATE:
after checking your log, I believe the problem can be here:
hailer.com.hailer.adapters.DiscussionAdapter.(DiscussionAdapter.java:57)
at
hailer.com.hailer.fragments.ChatListFragment.onCreateView(ChatListFragment.java:60)
Maybe in your ChatListFragment, you have an instance of DiscussionAdapter which in turn has some static initializer that invokes something related to Realm.
UPDATE 04/2017
The Samsung S7 started working couple of days after I posted this answer... Black magics all the way I say.
It seems that the Samsung S7 that I usually use for testing is somehow busted. I got some other phones from the office and all of them work just fine. I really have no idea what caused the phone to start crashing the app... None of the other apps are crashing and I didn't download any updates or other apps before this started. I'll post a comment to this answer if I figure this one out and accept this as the solution since I found a "solution"....

Categories

Resources