i'm new to android studio and my app is crushing besuase line of code
songProgressBar.setOnSeekBarChangeListener(this);
posting a question here helped me to realize it is a typo with an id in my layout. Well, here is the code for my layout with songProgressBar as an id.
<SeekBar
android:id="#+id/songProgressBar"
android:layout_width="fill_parent"
android:layout_height="25dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:layout_above="#id/player_footer_bg"
android:thumb="#drawable/seek_handler"
android:progressDrawable="#drawable/seekbar_progress_blue"
android:paddingLeft="6dp"
android:paddingRight="6dp"/>
Now, i don't know what the typo is, and i don't know what i'm to do. the person who told me it is a typo said i should check whether the component is present in the layout when the activity is running. I've got no idea what I'm to do now. pls help.
There seems to be a null pointer exception.
21:39:10.999 1443-1443/? E/AndroidRuntime: Caused by: java.lang.NullPointerException 01-10 21:39:10.999 1443-1443/? E/AndroidRuntime: at com.example.passion.patrimusic.MainActivity.onCreate(MainActivity.java:86) 01-10 21:39:10.999
And from your above comment, its possible that songProgressBar is null.
If you are getting it from the layout, check if there's any typo in the Id and whether the component is present in the layout when the activity is running.
Related
When I try to select text many times in the TextView, the application crashes with the error.
Does anyone know what could be the problem?
Error Stacktrace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: *** PID: 11481
java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
at android.text.SpannableStringInternal.checkRange(SpannableStringInternal.java:442)
at android.text.SpannableStringInternal.setSpan(SpannableStringInternal.java:163)
at android.text.SpannableStringInternal.setSpan(SpannableStringInternal.java:152)
at android.text.SpannableString.setSpan(SpannableString.java:46)
at android.text.Selection.setSelection(Selection.java:76)
at android.widget.Editor$SelectionModifierCursorController.resetDragAcceleratorState(Editor.java:5790)
at android.widget.Editor$SelectionModifierCursorController.onTouchEvent(Editor.java:5627)
at android.widget.Editor.onTouchEvent(Editor.java:1416)
at android.widget.TextView.onTouchEvent(TextView.java:9922)
at android.view.View.dispatchTouchEvent(View.java:11843)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
....
2019-07-28 16:00:53.369 11481-11481/? E/AndroidRuntime: at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4650)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4623)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7222)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7196)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7157)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7379)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:193)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:379)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:7383)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
Here is the markup for TextView:
<TextView
android:id="#+id/list_item_message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:gravity="center_vertical"
android:inputType="none"
android:linksClickable="true"
android:singleLine="false"
android:text="TextView"
android:lineSpacingExtra="3dp"
android:textIsSelectable="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
In the code I set the attribute: messageView.setMovementMethod (LinkMovementMethod.getInstance ());
I was able to reproduce only on android O and android N, in the following scenario:
Given a RecyclerView which presents a ViewHolder containing a TextView
That TextView as .setTextIsSelectable(true) and .setMovementMethod(LinkMovementMethod.getInstance())
Selecting a text from TextView and scrolling away from that particular view will cause crash. In particular, scrolling away while having presented that system overlay which offers "Copy", "Cut", "Paste", etc
So, my workaround (not a real solution but it will prevent crashes and it doesn't take users out of my app) was not allowing text selection on affected builds:
val selectable = when {
Build.VERSION.SDK_INT <= Build.VERSION_CODES.M -> true
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P -> true
else -> false
}
textView.setTextIsSelectable(selectable)
textView.setMovementMethod(LinkMovementMethod.getInstance())
remove this
android:lineSpacingExtra="3dp"
Try to specify android:inputType="text". As well, you can add android:autoLink="all"
I think this is a problem in the Android Framework. Similar to the one described here:
java.lang.IndexOutOfBoundsException: getChars (7 ... 0) has end before start
Because and I have a similar error too. Thank you all.
I just released an alarm app and it's been hell. It's breaking on certain devices when they try to open up the alarm list screen. I have no idea why it's breaking on some devices and not others. Every phone I've seen it tried on it works perfectly, but opening up the alarm list on some other devices blows it up. I'm really out of my depth for this kind of specific device compatibility issue.
The code at AlarmClock line 227 is this:
View changeSettings = findViewById(R.id.alarm_settings);
changeSettings.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
}
});
And it references this line of xml:
<Button
android:id="#+id/alarm_settings"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0.0dip" android:layout_height="fill_parent"
android:text="#string/menu_settings"
android:layout_weight="1.0" />
This links to a settings activity I borrowed the source of from an adapted version of the android stock alarm, but it uses addPreferencesFromResource which is allegedly deprecated. Is that what's causing this problem?
This is the stack trace from the user's device:
Nexus 7
Touched setup alarm button and then it crashed
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nathantempelman.GoodMorningAlarmFree/com.nathantempelman.alarmclockfree.AlarmClock}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
at android.app.ActivityThread.access$600(ActivityThread.java:142)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4931)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.nathantempelman.alarmclockfree.AlarmClock.updateLayout(AlarmClock.java:227)
at com.nathantempelman.alarmclockfree.AlarmClock.onCreate(AlarmClock.java:210)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
... 11 more
Any help would be splendiferous. I know that it's happened on someone else's tablet as well, not sure if it's a tablet issue.
The app is here if anyone wants to give it a test: https://play.google.com/store/apps/details?id=com.nathantempelman.GoodMorningAlarmFree
you have a NullPointerException in your AlarmClock class in updateLayout method in line 227 :)
Caused by: java.lang.NullPointerException
at com.nathantempelman.alarmclockfree.AlarmClock.updateLayout(AlarmClock.java:227)
at com.nathantempelman.alarmclockfree.AlarmClock.onCreate(AlarmClock.java:210)
i would check that code first.
as you didn't post any code, i cant help more at the moment :)
Just in case someone else stumbles across this, the problem in the end was that there was a separate layout file for tablets which I hadn't seen in the source codebase I borrowed for a part of my application. I had obviously added a bunch of functionality, but hadn't updated the tablet layout. The buttons to access the things I had added weren't in the tablet layout file. Ergo, null pointer exception only when a tablet device loaded the tablet layout file and searched for non existent objects in the display. When I deleted that file, everything worked perfectly.
I know, hurp and or durp. But maybe someone has the same problem and might want to check for this.
I've just started this evening into developing my first Android app and have come across an error that for the life of me I can't see where is coming from
When i launch my test app in the emulator it force closes with the error "The application Test App (psrocess Test.App) has stopped unexpectedly. Please try again."
So far I've checked: The Android Development output - nothing untoward,launches fine and locates activity and intent
The Emulator output - nothing reported at all
The TestApp debug - reports BUILD SUCCESSFUL
I proceeded to then examine the main.xml used for the layout and on validation in NetBeans it reports "cvc-elt.1: Cannot find the declaration of element 'LinearLayout'"
My main.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical" >
<Button
android:id="#+id/used_cars"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/used_cars" />
<Button
android:id="#+id/used_vans"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/used_vans" />
<Button
android:id="#+id/dealers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dealers" />
</LinearLayout>
I've trawled for info on how to fix this and can't find an answer
Could someone be kind enough to please advise if i'm missing something fundamental?
Thanks in advance
Barry
I've went through the logcat info and found nothing so i decided to create a new app from scratch and copy over the info and it runs fine
If i do find any other info on what caused the issue i'll be sure to post it up
I can only put it down to a config error atm
Kind Regards
Barry
I got the following crash report in the android market place. While testing I haven't found any crash and my app works fine. Once I published my app I got the following crash report which I have shown below.
But I am not able to find where the crash occurs, I checked in some stack overflow question and there in some cases I got that use of setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); make cause crash in some devices. Is it true because in my app in some activity I have used this line of code in order to change the input type of EditText from password-text / text-password?
Please help me to solve this out.
Stack Trace
java.lang.NullPointerException
at android.widget.TextView.onTouchEvent(TextView.java:7529)
at android.view.View.dispatchTouchEvent(View.java:3933)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:906)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1877)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1211)
at android.app.Activity.dispatchTouchEvent(Activity.java:2198)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1852)
at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2382)
at android.view.ViewRoot.handleMessage(ViewRoot.java:2010)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4385)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
<EditText
android:id="#+id/txt_edit_passwrd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_passwrd_title"
android:background="#drawable/img_password_textbox"
android:cursorVisible="true"
android:layout_marginTop="195dp"
android:hint="#string/passwrd_hint_text"
android:inputType="textPassword"
android:maxLength="10"
android:padding="10dp"
android:textColor="#121212" >
</EditText>
NullPointerException in my own experience tends to mean it cannot find a reference object for instance the edit text your setting the input type for cannot be found, check your layout references and how you've declared the EditText itself.
First check , Have you mention Minimum_sdk_version in android-manifest?
if not then following may be the reason of crashing your application--
If you are using that functionality of android o.s that does not support on customer device.Say you are using Finger_Pointer(as MotionEvent.ACTION_POINTER_DOWN) which does not support before android 2.0.
Or you are using onBackPressed() which does not support for android 1.6.I just gave you hint you can check other issue like this if you have
Updated
For HTC device, TextView's property InputType.TYPE_CLASS_NUMBER lead to crash
Here is the same problem discussed you can refer to this also.
The Solution is not to use "setInputType" with a TextView. You don't need input type filtering for TextViews anyway since they are for displaying text only. Input type is only needed for EditText (and there it works). I had the same problem with Android versions below 4.2.
The disadvantage is, that applying input type "password" on a textview actually makes sense as it masks the password, which may be intended (it was in my case). But this causes random crashes when touching or scrolling over the textview.
Using Android, here is part of a layout xml file:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:textColor="#191919">
<TextView android:id="#+id/someTextField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textStyle="bold" />
<TextView android:id="#+id/anotherTextField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
I am adding this view (at runtime) to a ViewAnimator like this:
ViewAnimator viewAnimator = (ViewAnimator)findViewById(R.id.viewAnimator);
View newView = View.inflate(this, R.layout.new_view, null);
viewAnimator.addView(newView);
viewAnimator.showNext();
String newValue = "new value for the text field";
findViewById(R.id.deal_view).setVisibility(View.VISIBLE);
TextView someTextField = (TextView)findViewById(R.id.someTextField);
someTextField.setText(newValue);
This seems to be working fine, but when newValue is long enough to take more than 1 line of text in the layout, I am getting a crash:
09-06 21:36:48.208: ERROR/AndroidRuntime(6561): Uncaught handler: thread main exiting due to uncaught exception
09-06 21:36:48.248: ERROR/AndroidRuntime(6561): java.lang.StackOverflowError
09-06 21:36:48.248: ERROR/AndroidRuntime(6561): at android.view.ViewGroup.drawChild(ViewGroup.java:1486)
09-06 21:36:48.248: ERROR/AndroidRuntime(6561): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1228)
(many more lines like this)
Is this enough information to see what I might be doing wrong? It works perfectly fine when newValue is short enough for one line. I've thought about trying a TableLayout but it seems like this is exactly what a LinearLayout is good for.
Thanks for the help in the comments. I ended up taking the advice here (dropping ViewAnimator directly and using ViewFlipper). Better app, but still the same problem. I dropped one level of LinearLayout containers and it started working fine.
I'm assuming bhatt4982 is right, UI depth was too great.
bhatt4982, post your comment as an answer to get credit for this.