Unable to start activity ComponentInfo{...} after installing Android SDK Build-Tools 26 - java

I upgraded Android Studio to 2.3.3
and then I installed Android SDK Build-Tools 26
and Android 8.0 (O)
and set compileSdkVersion and targetSdkVersion on 26
and buildToolsVersion on "26.0.0"
and then I changed all the libraries version from 25.3.1 to 26.0.0-alpha1
Now I have the below RunTime Exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mysite.myapp/com.mysite.myapp.MainActivity}: android.view.InflateException: Binary XML file line #35: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2480)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1377)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5725)
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:1030)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:825)
Caused by: android.view.InflateException: Binary XML file line #35: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.mysite.myapp.MainActivity.onCreate(MainActivity.java:65)
at android.app.Activity.performCreate(Activity.java:6018)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2370)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2480) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1377) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:155) 
at android.app.ActivityThread.main(ActivityThread.java:5725) 
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:1030) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:825) 
Caused by: java.lang.IllegalArgumentException: Setting FragmentDrawer{28990c1 #0 id=0x7f0f0095} as the target of FragmentDrawer{28990c1 #0 id=0x7f0f0095} would create a target cycle
at android.support.v4.app.Fragment.setTargetFragment(Fragment.java:636)
at com.mysite.myapp.Fragments.FragmentDrawer.onCreate(FragmentDrawer.java:83)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2226)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1502)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1737)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3512)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:330)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.mysite.myapp.MainActivity.onCreate(MainActivity.java:65) 
at android.app.Activity.performCreate(Activity.java:6018) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2370) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2480) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1377) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:155) 
at android.app.ActivityThread.main(ActivityThread.java:5725) 
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:1030) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:825) 
the (MainActivity.java:65) and (FragmentDrawer.java:83) are displayed as link.
MainActivity.java:65 content:
setContentView(R.layout.activity_main);
FragmentDrawer.java:83 content:
setTargetFragment(FragmentDrawer.this, 100);
before MainActivity there is a SplashActivity and it runs without any problem!
I've just downgraded SDK Build-Tools, compileSdkVersion, targetSdkVersion, buildToolsVersion and libraries version to run again and test. there is no problem using previews versions.
Can anyone help me? How can I run my App using new SDK Version?

The problem is here:
java.lang.IllegalArgumentException:
Setting FragmentDrawer{28990c1 #0 id=0x7f0f0095} as the target of
FragmentDrawer{28990c1 #0 id=0x7f0f0095} would create a target cycle
at android.support.v4.app.Fragment.setTargetFragment(Fragment.java:636)
setTargetFragment has changed in 26.0.0. Before, it simply set the target fragment plus request code. From 26.0.0 onwards, it contains two checks before doing that:
- it checks whether the current fragment and the target fragment belong to the same fragment manager
- it checks whether setting the target fragment would create a loop, by scanning the list of target fragments in this fragment and see if the target fragment is already there.
So somehow you are setting a target fragment that you set before. That is no longer allowed.

Related

How to get rid of the resource not found exception when clicked on item view on recycler view and instead of data and activity lauch, it crashes app

I have built an app to learn the use of adapter and recycler view.
It contains a recycler view and adapter, it uses data class to show data on clicked to an item of the recycler view, but the app crashes on runtime whenever I click on an item of the recycler view and showing java resources not found exception, could any one please help me out from this because I am a newbie to learning and debugging this
2022-07-24 16:00:14.903 11460-11460/com.example.planetapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.planetapp, PID: 11460
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.planetapp/com.example.planetapp.PlanetDetail}: android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3430)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
at android.os.Handler.dispatchMessage(Handler.java:112)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:292)
at android.content.res.Resources.getValue(Resources.java:1540)
at androidx.appcompat.widget.ResourceManagerInternal.createDrawableIfNeeded(ResourceManagerInternal.java:180)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:145)
at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:136)
at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:66)
at androidx.appcompat.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:91)
at androidx.appcompat.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:102)
at com.example.planetapp.PlanetDetail.setData(PlanetDetail.kt:37)
at com.example.planetapp.PlanetDetail.onCreate(PlanetDetail.kt:20)
at android.app.Activity.performCreate(Activity.java:7458)
at android.app.Activity.performCreate(Activity.java:7448)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1286)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3409)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199) 
at android.os.Handler.dispatchMessage(Handler.java:112) 
at android.os.Looper.loop(Looper.java:216) 
at android.app.ActivityThread.main(ActivityThread.java:7625) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)```
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.planetapp/com.example.planetapp.PlanetDetail}: android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
The error above tells you what is really happening.
You are trying to access a "resource" using findViewById(int id) when it's not existing at all.
I recommend double-checking your code that uses findViewById(...) especially the code that intercepts the onClick(View view) event.
For example if you have an xml element with an ID like this:
<... android:id="#+id/MY_EXCELLENT_ID" ... />
You might've typed it like this:
findViewById(R.id.MY_EXCELLEND_ID);

How to get path to current class file in Kotlin in Android app without getProtectionDomain

I need to get 2 things logged from the current line of code:
the current class which is currently executed
the full path to the file of this class
In Kotlin, I can get class by
this::class
or
this::class.java
Then, I should be able to get path to the file of the class via
class.getProtectionDomain().getCodeSource().getLocation().getPath()
As is advised e. g. here.
The problem is getProtectionDomain returns null for Android Activity:
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414)
at android.view.View.performClick(View.java:7288)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View.performClickInternal(View.java:7258)
at android.view.View.access$4000(View.java:808)
at android.view.View$PerformClick.run(View.java:28019)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7615)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
at android.view.View.performClick(View.java:7288) 
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119) 
at android.view.View.performClickInternal(View.java:7258) 
at android.view.View.access$4000(View.java:808) 
at android.view.View$PerformClick.run(View.java:28019) 
at android.os.Handler.handleCallback(Handler.java:883) 
at android.os.Handler.dispatchMessage(Handler.java:100) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7615) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 
Caused by: java.lang.NullPointerException: this::class.java.protectionDomain must not be null
Meanwhile the class is of course not null because I can successfully see its name
log(this::class.java.name)
So how can i get class file path without getProtectionDomain?

proguard rules for tenor sdk

Can anyone Provide proguard rules for Tenor Sdk android. There are no rules provided for there sdk on git. The link for git repository is :
https://github.com/Tenor-Inc/tenor-android-core
Following is the crash exception I am getting :
FATAL EXCEPTION: main
Process: com, PID: 14520
java.lang.RuntimeException: Unable to start activity ComponentInfo{com/com.ui.activities.GifListActivity}: java.lang.IllegalArgumentException: Unable to create converter for class com.tenor.android.core.d.a.c
for method d.a
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2434)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
at android.app.ActivityThread.access$900(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5525)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: java.lang.IllegalArgumentException: Unable to create converter for class com.tenor.android.core.d.a.c
for method d.a
at h.n$a.a(ServiceMethod.java:752)
at h.n$a.c(ServiceMethod.java:738)
at h.n$a.a(ServiceMethod.java:169)
at h.m.a(Retrofit.java:170)
at h.m$1.invoke(Retrofit.java:147)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at $Proxy0.a(Unknown Source)
at com.i.b.a(GiffRetrievalService.java:38)
at com.ui.activities.GifListActivity.a(GifListActivity.java:93)
at com.ui.activities.GifListActivity.a(GifListActivity.java:63)
at com.ui.activities.GifListActivity.onCreate(GifListActivity.java:58)
at android.app.Activity.performCreate(Activity.java:6272)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)
... 9 more
Caused by: java.lang.IllegalArgumentException: class com.tenor.android.core.b.a.b declares multiple JSON fields named a
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(ReflectiveTypeAdapterFactory.java:170)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(ReflectiveTypeAdapterFactory.java:100)
at com.google.gson.f.a(Gson.java:423)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(ReflectiveTypeAdapterFactory.java:115)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(ReflectiveTypeAdapterFactory.java:164)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(ReflectiveTypeAdapterFactory.java:100)
at com.google.gson.f.a(Gson.java:423)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.a(CollectionTypeAdapterFactory.java:53)
at com.google.gson.f.a(Gson.java:423)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(ReflectiveTypeAdapterFactory.java:115)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(ReflectiveTypeAdapterFactory.java:164)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(ReflectiveTypeAdapterFactory.java:100)
at com.google.gson.f.a(Gson.java:423)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.a(CollectionTypeAdapterFactory.java:53)
at com.google.gson.f.a(Gson.java:423)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(ReflectiveTypeAdapterFactory.java:115)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(ReflectiveTypeAdapterFactory.java:164)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(ReflectiveTypeAdapterFactory.java:100)
at com.google.gson.f.a(Gson.java:423)
at h.a.a.a.a(GsonConverterFactory.java:64)
at h.m.a(Retrofit.java:330)
at h.m.b(Retrofit.java:313)
at h.n$a.c(ServiceMethod.java:736)
... 21 more
Thanks
Use this rule
-keep class com.tenor.android.core.** { *; }
This will keep away all classed inside com.tenor.android.core package from getting proguarded

Why does app crash on start only on api 26

I have an app working on every api completely but in android 8 api 26 it crashes and I don't know why this happend .
The app use sms sending and receiving permissions and I put all requestPermissions in activity and manifests. Target sdk is on 26
Here the logcat of android studio error when app crash:
hapital.com.BitCar E/AndroidRuntime: FATAL EXCEPTION: main Process: hapital.com.BitCar, PID: 25271
java.lang.RuntimeException: Unable to start activity ComponentInfo{hapital.com.BitCar/hapital.com.BitCar.MainActivity}: java.lang.IllegalArgumentException: Invalid destinationAddress
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalArgumentException: Invalid destinationAddress
at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:320)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:312)
at hapital.com.BitCar.MainActivity.onCreate(MainActivity.java:194)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6541) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Invalid destinationAddress ?? what does it mean??
For example it has an error on SmsManager.java when open it just like pic below has error in import libraries
enter image description here
Could someone help what should i do?
According to the source code of SmsManager, that exception is thrown when you call sendTextMessage with a destination address parameter that is null or an empty String.
If your code to send the SMS (as per your comment) is this:
SharedPreferences panelnumber = getSharedPreferences("Prefs", MODE_PRIVATE);
String string_from_sp = panelnumber.getString("myStringName", "");
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(string_from_sp.toString(), null,
smsBody.toString(), null, null);
then it follows that string_from_sp is a null or empty String.
Given the way you are initializing that variable, either:
the "mystringName" field retrieved from the preferences is empty, or
you have the preference field name incorrect, and you are getting the default value which you have specified to be an empty String.
There is not sufficient info to explain why this happens with API 26 only ... if that is what you are saying.
finally i found the problem
problem was in layout of activity that i used NavigationView like belo :
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="230dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main2"
app:menu="#menu/activity_main2_drawer" />
and in api 26 and higher not support

Android Studio - Application has stopped, but 0 code errors

My android application was running smoothly before i install some Android Studio updates, and asked me to upgrade gradle etc after the update been installed.
Later on, the Android Studio asked me to update my Android Emulator (Emulator Nexus 5X API 24 Android v7.0), since i've made all these changes, my application has been unable to open when i click run. But remember it has no codding errors when i debug etc.
The error message from Android Monitor is:
08-13 14:07:30.735 3889-3889/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.smartlegal.law.freeman.smartlegal, PID: 3889
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartlegal.law.freeman.smartlegal/com.smartlegal.law.freeman.smartlegal.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
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: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.smartlegal.law.freeman.smartlegal.MainActivity.onCreate(MainActivity.java:39)
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)
08-13 14:07:30.744 3889-3896/? W/art: Suspending all threads took: 5.874ms
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
As the error states, you're trying to set an onClickListener on a Button that does not exist (returns null). To simplify, when you're defining your Button, you call findViewById to associate the Button in Java with an XML element, but the ID that you are passing is not valid - either you're trying to call the setOnClickListener before you call setContentView, or the ID you are passing to findViewById has a typo or simply does not exist in the XML layout file.
Some more information, such as the code to your MainActivity and the layout file, would be useful to determine the exact cause of your problem.
Yes you're right, i forgot to specify the ID for the editText and Button, that is why it wasnt possible to find them ID on XML. So i've set it up and reloaded the project and it is running smoothly now. Thanks guys for the support.
"As the error states, you're trying to set an onClickListener on a Button that does not exist (returns null). To simplify, when you're defining your Button, you call findViewById to associate the Button in Java with an XML element, but the ID that you are passing is not valid. by: Timothy Langer".

Categories

Resources