hey guys i want to transfer my searchview from actionbar to inside of my android layout but when im transfering it ill get crashed. how to fix this problem? thanks for any help.
here is my logcat
04-12 19:57:28.277 25122-25122/com.example.lightning.myapplication3 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.lightning.myapplication3, PID: 25122
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lightning.myapplication3/com.example.lightning.myapplication3.SetRouteActivity}: java.lang.ClassCastException: android.widget.SearchView cannot be cast to android.support.v7.widget.SearchView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2584)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2650)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1505)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
Caused by: java.lang.ClassCastException: android.widget.SearchView cannot be cast to android.support.v7.widget.SearchView
at com.example.lightning.myapplication3.SetRouteActivity.onCreate(SetRouteActivity.java:53)
at android.app.Activity.performCreate(Activity.java:6270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2537)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2650)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1505)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
What you receive is a ClassCastException
This means, the type you use is wrong.
searchView = (SearchView)findViewById(R.id.pointa);
You have two choices:
1) Look for the import statement of SearchView at the top of this class file and change it from android.widget.SearchView to android.support.v7.widget.SearchView (or the other way round).
2) Take a close look at your XML file, looking for the <SearchView Tag. Is it possible, that because of the move, it changes from widget to support SearchView?
One of those two will fix your problem.
Hope this helps.
Related
I'm getting this annoying exception in my main activity sometimes.
the stack trace is like this:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tomatedigital.lottogram, PID: 4430
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 543588 bytes
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4156)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: android.os.TransactionTooLargeException: data parcel size 543588 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:761)
at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:5147)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4148)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
The trace itself is not very helpfull since it doesn't specify which component or what transaction Id or Tag is related to the Exception (google please think about the debuggability of the crap you put out there)...
but i do suspect it is the recycleview i have in my main activity.
This recycleview might get super loaded, THOUSANDS of items. each of them contains: 3 small strings, 1 large string and one small bitmap.
When this recyclerview is overloaded and the activity is suspended this exception is thrown. Since the recyclerview is created inflating the layout.xml, android do save its state automaticly.
Is there any easy way to workaround this problem?
Is possible to set the App to allow "super large Transaction"?
What can i do?
================UPDATE===================
to provide aditional information about my Activity
#Override
protected void onSaveInstanceState(#NonNull Bundle outState) {
outState.putSerializable("media", this.media); //this is a domain class
outState.putBoolean("canceled", this.canceled);
outState.putInt("speed", this.speed);
outState.putLong("startTime", this.startTime);
outState.putSerializable("comments", (Serializable) this.adapter.getList()); //this is the large data
outState.putBoolean("commentLoadComplet", this.complete);
outState.putSerializable("fetched", (Serializable) this.fetched);
outState.putSerializable("igiboAttendees", (Serializable) this.igiboAttendees);
outState.putLong("winnerId", this.winnerId);
super.onSaveInstanceState(outState);
}
This is typically caused by saving large amounts of data in onSaveInstanceState, not only for the activity in which the exception occurred, but also in other activities currently in the back stack.
One solution is to use the ViewModel class to maintain state instead of onSaveInstanceState:
ViewModel Overview
You may still use onSaveInstanceState for small amounts of data, but keep in mind it adds up over all the activities.
I have created a Linear Layout onclick of a button which has an edit text. While typing there is a popup window for suggestions that comes up and the app crashes.
Stack trace:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.widget.Editor$SuggestionsPopupWindow.initContentView(Editor.java:3714)
at android.widget.Editor$PinnedPopupWindow.(Editor.java:3375)
at android.widget.Editor$SuggestionsPopupWindow.(Editor.java:3660)
at android.widget.Editor.replace(Editor.java:423)
at android.widget.Editor$3.run(Editor.java:2340)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
I found some related answers which stated that this happens on using Android PopupWindow class since the suggestions are using a PopupWindow as well. My code does not use PopupWindow as well.
This crash is happening mostly on Samsung Note 5, and Galaxy S6.
Any help would be appreciated!
It's saying that your button (which you used like buttonName.setOnClickListener()) is not defined. Check your find view by id function, id inside of it etc.
I think it is because you set in XML a click, but don't have in your class. A check has this tag and remove:
android:onClick="save"
I have looked everywhere and there are only so many people that have asked this question and so far nothing is working. I am currently working on an app that is based on fragments and when someone enters their id, it downloads their name and picture. I want to be able to change their name in the nav header field. Currently this is the code I am using
View header = LayoutInflater.from(getActivity()).inflate(R.layout.nav_header_main, null);
navigationView.addHeaderView(header);
test = (TextView) header.findViewById(R.id.username);
test.setText("HELLO");
That I obtained from here https://code.google.com/p/android/issues/detail?id=190786
I also tried this method here In android how to set navigation drawer header image and name programmatically in class file?
Both of these end up with this error
FATAL EXCEPTION: main
Process: com.horizonservers.horizon, PID: 4042
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.horizonservers.horizon/com.horizonservers.horizon.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.NavigationView.addHeaderView(android.view.View)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
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.NullPointerException: Attempt to invoke virtual method 'void'
android.support.design.widget.NavigationView.addHeaderView(android.view.View)' on a null object reference
at com.horizonservers.horizon.MainFragment.onCreateView(MainFragment.java:153)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237)
at android.app.Activity.performStart(Activity.java:6253)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
Does anyone know how to change the Text and image of the nav header side bar? https://gyazo.com/23534130df4aff888708415b368aa1fa
NavigationView navigationView = findViewById(R.id.nav_view);
View header = navigationView.getHeaderView(0);
test = (TextView) header.findViewById(R.id.username);
test.setText("HELLO");
Maybe this would help!!
If anyone finds this in the future, I was able to find a library that does pretty much exactly what I needed it to do. You can find it here.
Based on your error, it looks like navigationView is null. Check to make sure navigationView was properly initialized BEFORE you inflate the header. Depending on how/where you're using fragments, the fragment lifecycle could be initializing the navigationView after the header inflation which will throw a NullPointerException.
If not the above, navigation header inflation has become very sensitive to the android environment used with recent design changes to the google design library. Below was my all-inclusive solution, and maybe it will work for you.
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
View header = navigationView.inflateHeaderView(R.layout.nav_header_main);
test = (TextView) header.findViewById(R.id.username);
test.setText("HELLO");
I'm trying to make change a TextView 's text by the value submitted from a EditText on a Dialog.
There's one Dialog that makes you Add the amount and on makes you Remove it from the TextView.
What I don't get is why when I click on 'Add' or 'Remove' the app crashes.
Here's the entire Code (Java and XMLs)
http://pastebin.com/er3zTe4V
-- Error --
09-14 20:49:55.661 31774-31774/com.hfad.pocket E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.hfad.pocket, PID: 31774
java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at com.hfad.pocket.MainActivity$1.onClick(MainActivity.java:32)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:163)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
Since your EditText is in the dialog layout, you need to call findViewById on your dialog:
EditText transaction = (EditText) ((AlertDialog) dialog).findViewById(R.id.editText);
I need to set background color to the circle image view of swiperefreshlayout
It always gives an exception :
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobile.clubgecko.beta/com.mobile.clubgecko.activities.ClubGeckoBaseActivity}: android.content.res.Resources$NotFoundException: Resource ID #0xfffd6c00
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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)
I have used following but no luck
swipeRefreshLayout.setProgressBackgroundColor(Color.parseColor("#fd6c00"));
swipeRefreshLayout.setProgressBackgroundColor(context.getResources().getColor(R.color.geckocolor));
I looked up the code on GrepCode
453 public void More ...setProgressBackgroundColor(int colorRes) {
454 mCircleView.setBackgroundColor(colorRes);
455 mProgress.setBackgroundColor(getResources().getColor(colorRes));
456 }
They use getResources().getColor() to retrieve the color. If you provide a real color, not a resource id, the look up fails (as per exception). You have to provide a resource id of the color. Change from
swipeRefreshLayout.setProgressBackgroundColor(context.getResources().getColor(R.color.geckocolor));
to
swipeRefreshLayout.setProgressBackgroundColor(R.color.geckocolor);
Try setProgressBackgroundColorSchemeColor(), setProgressBackgroundColor() is deprecated.
https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html#setProgressBackgroundColor(int)
The old deprecated method is expecting a resource id, but you're passing a color value.