Starting new Activity by clicking on Button in Toolbar - android

Maybe it's a simple question but I can't get the answer, although I searched for hours and more in google, etc.
I set up two activities and two layouts - main(background white), second(background black).
Then I set up a new resource file in the layout folder called toolbar:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black">
<Button
android:id="#+id/profile_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="start"
android:text="Profile" />
</android.support.v7.widget.Toolbar>
My question now is:
Where do I put the method to start the second activity by pressing the button in my toolbar? and how do I do it?
Tried it with onClick in the XML file and a method in the MainActivity OR with a OnClickListenerMethod in the MainActivity class.
I have this:
public void start(View view) {
Intent intent = new Intent(this, ProfileActivity.class);
startActivity(intent);
}
But I got errors and my App shut down: NullPointerException and IllegalStateException
Hope you guys will help me, cause I just started with Java!
Edit: The only method in main and second activity is the onCreate Method with super.onCreate and setContentView. Maybe I have to add something?
Here is the error:
 
05-02 23:48:23.533 17050-17050/com.example.timomichel.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.timomichel.myapplication, PID: 17050
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:289)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:5198) 
at android.view.View$PerformClick.run(View.java:21147) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.timomichel.myapplication/com.example.timomichel.myapplication.SecondActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1794)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:843)
at android.app.Activity.startActivity(Activity.java:4200)
at android.app.Activity.startActivity(Activity.java:4168)
at com.example.timomichel.myapplication.MainActivity.start(MainActivity.java:18)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284) 
at android.view.View.performClick(View.java:5198) 
at android.view.View$PerformClick.run(View.java:21147) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Declare SecondActivity in your AndroidManifest.xml:
<activity android:name="com.example.timomichel.myapplication.SecondActivity">
....
</activity>

Related

Hardcoded app:fragment string in Preference crashes in Release

Below is the simplified version of the xml file for my settings screen.
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--hardcoded app:fragment crashes in release because of ClassNameNotFound -->
<Preference
app:allowDividerAbove="true"
app:fragment="com.flamyoad.tsukiviewer.ui.settings.preferences.ClearDataPreferences"
app:icon="#drawable/ic_delete_settings_24dp"
app:title="Clear data" />
</androidx.preference.PreferenceScreen>
It works well in debug version. But when I click on the preference on release apk, it crashes because of ClassNotFoundException.
Stacktrace here
Process: com.flamyoad.tsukiviewer, PID: 13647
androidx.fragment.app.Fragment$c: Unable to instantiate fragment com.flamyoad.tsukiviewer.ui.settings.preferences.ClearDataPreferences: make sure class name exists
at i.l.d.n.d()
at androidx.fragment.app.Fragment.a()
at i.l.d.r$c.a(:2)
at com.flamyoad.tsukiviewer.ui.settings.SettingsActivity.a(:2)
at i.s.f.b(:29)
at androidx.preference.Preference.a(:23)
at androidx.preference.Preference$a.onClick()
at android.view.View.performClick(View.java:4757)
at android.view.View$PerformClick.run(View.java:19769)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5289)
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.ClassNotFoundException: com.flamyoad.tsukiviewer.ui.settings.preferences.ClearDataPreferences
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at i.l.d.n.c(:2)
at i.l.d.n.d() 
at androidx.fragment.app.Fragment.a() 
at i.l.d.r$c.a(:2) 
at com.flamyoad.tsukiviewer.ui.settings.SettingsActivity.a(:2) 
at i.s.f.b(:29) 
at androidx.preference.Preference.a(:23) 
at androidx.preference.Preference$a.onClick() 
at android.view.View.performClick(View.java:4757) 
at android.view.View$PerformClick.run(View.java:19769) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5289) 
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.ClassNotFoundException: Didn't find class "com.flamyoad.tsukiviewer.ui.settings.preferences.ClearDataPreferences" on path: DexPathList[[zip file "/data/app/com.flamyoad.tsukiviewer-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:308) 
at i.l.d.n.c(:2) 
at i.l.d.n.d() 
at androidx.fragment.app.Fragment.a() 
at i.l.d.r$c.a(:2) 
at com.flamyoad.tsukiviewer.ui.settings.SettingsActivity.a(:2) 
at i.s.f.b(:29) 
at androidx.preference.Preference.a(:23) 
at androidx.preference.Preference$a.onClick() 
at android.view.View.performClick(View.java:4757) 
at android.view.View$PerformClick.run(View.java:19769) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5289) 
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) 
Suppressed: java.lang.ClassNotFoundException: com.flamyoad.tsukiviewer.ui.settings.preferences.ClearDataPreferences
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 21 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
To me, it looks like the cause is the apk being minified and class name is replaced with shorter string. What can I do in this situation? Is it best practice to replace the app:fragment with function calls in Activity? Or is there any other methods?
I'm using PreferenceFragmentCompat for my application.
The aapt2 generated proguard rules for preferences specifically look for the android:fragment attribute, not app:fragment. You'd want to use android:fragment to automatically keep preference fragments.
I added these lines into my proguard-rules.pro and it stopped crashing.
-keep public class * extends androidx.preference.Preference
-keep public class * extends androidx.preference.PreferenceFragmentCompat

Android in app biling Can't start async operation

I am new in android, my first app has finished recently. I want to set an IAB (in app billing) in my app,I tested my app and I had the below problems:
1-when I click on the "buy" button eveything is OK and the pay operation run correctly. but when I close the app and click on button I have below errors.
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:4015)
at android.view.View.performClick(View.java:4764)
at android.view.View$PerformClick.run(View.java:19844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5376)
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:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4010)
at android.view.View.performClick(View.java:4764) 
at android.view.View$PerformClick.run(View.java:19844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5376) 
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:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.IllegalStateException: Can't start async operation
(launchPurchaseFlow) because another async operation(refresh inventory) is in progress.
at
com.example.android.trivialdrivesample.util.IabHelper.flagStartAsync(IabHelper.java:812)
at com.example.android.trivialdrivesample.util.IabHelper.launchPurchaseFlow(IabHelper.java:376) at com.example.android.trivialdrivesample.util.IabHelper.launchPurchaseFlow(IabHelper.java:341) at com.example.farshid.columnanalysis.MainActivity.gotoColumnAnalysis(MainActivity.java:186) at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at android.view.View$1.onClick(View.java:4010) at android.view.View.performClick(View.java:4764)  at android.view.View$PerformClick.run(View.java:19844)  at android.os.Handler.handleCallback(Handler.java:739)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5376)  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:908) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703) 
2-I have another question :) how can I change my button background when sb buy my app(for example change its test from Buy to Read)
how can I fix them... tnx in advanced.

Application crashes when run on other devices

I'm having a problem with Android Studio and testing my application. I'm testing it on two identical One Plus One devices. It works fine on the one I've been using since the start, but today I tested it on the second device and it crashes when it gets to a certain part of the app.
The app in question connects two or more devices using Google Play services real time multiplayer. One the first device, it's searching for peers to play with. The second device was to test that they can connect.
However, when the button is clicked to search for devices, it crashes the app.
I will print the logs below, but I'm wondering is there some other reason why this happens? Why it works on the device I've used from the start, but doesn't on the exact same device?
Any help is GREATLY appreciated. It's really hindering my progress and Google hasn't returned much in the line of helpful results.
Logs:
03-30 17:21:49.330 10436-10436/com.example.anna.pokerapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.anna.pokerapp, PID: 10436
Theme: themes:{default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21158)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5204) 
at android.view.View$PerformClick.run(View.java:21158) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5461) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.IllegalStateException: GoogleApiClient must be connected.
at com.google.android.gms.common.internal.zzac.zza(Unknown Source)
at com.google.android.gms.games.Games.zzb(Unknown Source)
at com.google.android.gms.games.Games.zzi(Unknown Source)
at com.google.android.gms.games.internal.api.RealTimeMultiplayerImpl.getSelectOpponentsIntent(Unknown Source)
at com.example.anna.pokerapp.QuickGame.onStartMatchClicked(QuickGame.java:50)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
at android.view.View.performClick(View.java:5204) 
at android.view.View$PerformClick.run(View.java:21158) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5461) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

Excute URL get, Error when executing urlget

I want to excute a simple url get, I used the code inside this link
http://developer.android.com/reference/java/net/HttpURLConnection.html
I want to run this code inside a click event:
URL url = new URL("http://www.android.com/");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);}
finally {
urlConnection.disconnect();
}
When I run the app I am getting this long error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.soma.smsserver1, PID: 20664
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:289)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:5198) 
at android.view.View$PerformClick.run(View.java:21147) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)
at java.net.InetAddress.lookupHostByName(InetAddress.java:431)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:188)
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:157)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:100)
at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:357)
at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:340)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:433)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:384)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:231)
at com.example.soma.smsserver1.MainActivity$override.clickMe(MainActivity.java:28)
at com.example.soma.smsserver1.MainActivity$override.access$dispatch(MainActivity.java)
at com.example.soma.smsserver1.MainActivity.clickMe(MainActivity.java:0)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284) 
at android.view.View.performClick(View.java:5198) 
at android.view.View$PerformClick.run(View.java:21147) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)
you cannot process networking on the main thread, this is a security restriction on Android, try wrapping your call in AsyncTask a background service, or thread.
Please read documentation regarding Processes and Threads
You are doing a network Request on the MainThread, which is prohibited because it would block the UI during this call.
You should use an other Thread to do this call, you have different options : Thread, AsyncTask, etc ...
Some examples here :
http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html
you are handling network on Main Thread which will make your app hang so, you need to handle long running task on background service like AsyncTask
check this link https://www.upwork.com/hiring/mobile/why-you-should-use-asynctask-in-android-development/

Unable to display EditText error in Kotlin code

I have switched my Android development over to Kotlin, but I am dealing with a crash that I can't figure out. I am used to, in Java, being able to display an error on an empty EditText:
if(mEmail.getText().toString().isEmpty()) {
mEmail.setError("Email cannot be blank.");
}
To the best of my knowledge, that could be translated to Kotlin as:
if(email.text.toString().isEmpty()) {
email.error = "Email cannot be blank."
}
However, that doesn't work, and I get the following stack trace:
Process: com.androidessence.capturethetag, PID: 4016
android.view.InflateException: Binary XML file line #17: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.widget.Editor.showError(Editor.java:319)
at android.widget.Editor.setError(Editor.java:355)
at android.widget.TextView.setError(TextView.java:4648)
at android.widget.TextView.setError(TextView.java:4633)
at com.androidessence.capturethetag.activities.LoginActivity.validateInput(LoginActivity.kt:31)
at com.androidessence.capturethetag.activities.LoginActivity.access$validateInput(LoginActivity.kt:12)
at com.androidessence.capturethetag.activities.LoginActivity$onCreate$1.onClick(LoginActivity.kt:19)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 24
at android.content.res.TypedArray.getColor(TypedArray.java:401)
at android.widget.TextView.<init>(TextView.java:696)
at android.widget.TextView.<init>(TextView.java:632)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:60)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:92)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:938)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:992)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.widget.Editor.showError(Editor.java:319) 
at android.widget.Editor.setError(Editor.java:355) 
at android.widget.TextView.setError(TextView.java:4648) 
at android.widget.TextView.setError(TextView.java:4633) 
at com.androidessence.capturethetag.activities.LoginActivity.validateInput(LoginActivity.kt:31) 
at com.androidessence.capturethetag.activities.LoginActivity.access$validateInput(LoginActivity.kt:12) 
at com.androidessence.capturethetag.activities.LoginActivity$onCreate$1.onClick(LoginActivity.kt:19) 
at android.view.View.performClick(View.java:4780) 
at android.view.View$PerformClick.run(View.java:19866) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
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:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
Any ideas why this is crashing in Kotlin?
EDIT
For more information, you can see my content_login.xml file here. I've used Gist to save space.
Also, I never call findViewById(); on my EditText because the Kotlin-Android Extension Plugin can do it, as mentioned here: https://kotlinlang.org/docs/tutorials/android-plugin.html
I have no doubts that it's referencing the right EditText, because logging showed me that it was able to determine the EditText was empty, but is unable to set the error attribute.

Categories

Resources