Espresso can't click displayed view - android

Overnight my ui tests stopped working all of a sudden:
Line in barista clickOn(R.id.myView) throws:
com.schibsted.spain.barista.internal.failurehandler.BaristaException: Could not perform action single click on view with id: [...]
[...]
Caused by: androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (is displayed on the screen to the user and with id: [...]
Line in Espresso onView(withId(R.id.myView)).perform(scrollTo(), click()) throws:
androidx.test.espresso.PerformException: Error performing 'single click - At Coordinates: 53, 1723 and precision: 16, 16' on view 'Animations or transitions are enabled on the target device.
[...]
Caused by: java.util.NoSuchElementException: List is empty.
I don't understand why this happens. I can see the view on screen during the test and espresso gave me some coordinates.
Edit:
Since it's a TextView I also tried Baristas clickOn(context.getString(R.string.myText)) but it throws:
com.schibsted.spain.barista.internal.failurehandler.BaristaException: Could not perform action single click on view with text: is [...]
[...]
Caused by: androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (is displayed on the screen to the user and with text: is [...]
<TextView
android:id="#+id/myView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/myText"/>

The error is unrelated to Espresso or Barista.
java.util.NoSuchElementException: List is empty was thrown in the OnClickListener of the view.

Related

My App is Crashing while using google maps in my flutter application

Here is the error while crashing:-
Process: com.example.basic_setup, PID: 13613
java.lang.NullPointerException: Attempt to get length of null array
at java.nio.ByteBufferAsIntBuffer.put(ByteBufferAsIntBuffer.java:122)
at com.google.maps.api.android.lib6.gmm6.vector.gl.buffer.n.i(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):2)
at com.google.maps.api.android.lib6.gmm6.vector.gl.buffer.n.d(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):3)
at com.google.maps.api.android.lib6.gmm6.vector.gl.drawable.d.s(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):2)
at com.google.maps.api.android.lib6.gmm6.vector.gl.drawable.ao.s(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):12)
at com.google.maps.api.android.lib6.gmm6.vector.bz.s(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):29)
at com.google.maps.api.android.lib6.gmm6.vector.bs.b(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):151)
at com.google.maps.api.android.lib6.gmm6.vector.av.run(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):48)
I am getting error while navigating fastly from another screen to map screen in bottom navigation bar.
this is the known issue in map v2:
https://issuetracker.google.com/issues/35829536
Use SupportMapFragment in xml file instead of mapview. eg :
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
for more infmormation follow these links :
https://developers.google.com/android/reference/com/google/android/gms/maps/SupportMapFragment
https://developers.google.com/maps/documentation/android-api/map

Android: lazy-loading of DataBinding view throws exception

There is a large data-bound view, which may take several seconds to inflate. I would like to display the user a splash screen and inflate the main view a delayed action. Android studio throws an exception "Failed to call observer method".
MainActivity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.screen_splash)
Handler(Looper.getMainLooper()).postDelayed({
val binding = DataBindingUtil.setContentView<ActivityMainBinding>(
this,
R.layout.activity_main
)
binding.lifecycleOwner = this // this line throws exception
}, 1000)
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="vm"
type="com.example.ViewModel"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/map_list"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" />
</RelativeLayout>
Exception:
2021-12-05 13:42:56.638 23701-23701/com.example E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example, PID: 23701
java.lang.RuntimeException: Failed to call observer method
at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:226)
at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:194)
at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:185)
at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:37)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196)
at androidx.databinding.ViewDataBinding.setLifecycleOwner(ViewDataBinding.java:434)
at com.example.databinding.ActivityMainBindingImpl.setLifecycleOwner(ActivityMainBindingImpl.java:166)
at com.example.MainActivity.onCreate$lambda-3(MainActivity.kt:106)
at com.example.MainActivity.$r8$lambda$lffeScwTEbHi2B1isKEoQYU2po4(Unknown Source:0)
at com.example.MainActivity$$ExternalSyntheticLambda5.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:888)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
Caused by: java.lang.NumberFormatException: s == null
at java.lang.Integer.parseInt(Integer.java:577)
at java.lang.Integer.valueOf(Integer.java:801)
at com.example.databinding.ControlPanelBindingImpl.executeBindings(ControlPanelBindingImpl.java:800)...
I am not sure about the structure of your application. In our case we had a similar requirement where we wanted to show a loader until the initial fragment is bound. So we created a viewStub in the activity. Then when the fragment is attached we set a liveData in the shared view model to SHOW which notifies the activity to inflate the viewStub. This way we inflate the view stub which hides the full screen displaying a splash image. Then once the view in the fragment is created and in the onViewCreated we again set the liveData in the shared view model to HIDE which hides the viewStub and the fragment is displayed.
Use fragmentContainerView inside your main activity. Show the view that you want to show in this container. Create a view in front of the container. Show splash message in this view. Make the visibility of the splash view gone when the main view is loaded. So the splash screen will use the activity life cycle and the main view will use the fragment lifecycle. This may be a solution for you.
Disclaimer: turns out that the issue is resolved in UPDATE 2 section
in the answer; the other sections are left if they could help future visitors in other potential issues
At first look, thought that Caused by: java.lang.NumberFormatException: s == null is related to the issue; although you told in comments that it's working synchronously.
And the exception java.lang.RuntimeException: Failed to call observer method won't help to know the error by tracing it in the code.
But your code successfully worked with me in simple layouts; probably the issue is related to the heavy layout that you try to load synchronously along while accessing the binding.lifecycleOwner; I guess the latter snippet requires a while before accessing the lifecycleOwner. So, you could post some delay in advance.
For that, I am going to use coroutines instead of posting a delay; as the code would be more linear and readable:
CoroutineScope(Main).launch {
delay(1000) // Original delay of yours
val binding = DataBindingUtil.setContentView<ActivityMainBinding>(
this#MainActivity,
R.layout.activity_main
)
delay(1000) // try and error to manipulate this delay
binding.lifecycleOwner = this#MainActivity
}
If not already used, the coroutine dependency is
def coroutine_version = "1.5.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"
UPDATE
The posted delay in your code doesn't help in showing the splash/launch screen during that delay while the main activity is loading;
Handler(Looper.getMainLooper()).postDelayed({
val binding = DataBindingUtil.setContentView<ActivityMainBinding>(
this,
R.layout.activity_main
) // This won't be called unless the 1000 sec is over
binding.lifecycleOwner = this
}, 1000)
What your code does:
A splash screen is shown
A delay is posted (still the main layout is not loading in here)
main layout is shown when the delay is over
So, the posted delay is just accumulating to the time of loading the main layout; this even make it more lagged. Furthermore this is not the recommended way of using splash screen (This medium post would help in that)
Instead, I think what you intend to do:
Show a splash screen
Load main layout
Post a delay so that the main layout takes time to load during the delay
Show the main layout when the delay is over
But, the problem is that the thing need to be loaded is UI which requires to do that in the main thread, not in a background thread. So, we instead of using two different layout and call setContentView() twice; you could instead create a single layout for your main layout, and add some view that represents the splash screen which will obscure the main layout entirely (be in front of it) until the layout is loaded (i.e. the delay is over); then remove this splash view then:
Demo:
splash_screen.xml (Any layout you want that must match parent to obscure it):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/splash_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
Main activity:
class MainActivity : AppCompatActivity() {
companion object {
const val TAG = "LOG_TAG"
}
lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d(TAG, "Start Inflating layout")
binding = DataBindingUtil.setContentView(
this#MainActivity,
R.layout.activity_main
)
// Show only the first time app launches, not in configuration changes
if (savedInstanceState == null) {
CoroutineScope(IO).launch {
Log.d(TAG, "Start of delay")
delay(1000)
Log.d(TAG, "End of delay")
withContext(Main) {
hideSplash()
}
}
showSplash()
}
binding.lifecycleOwner = this#MainActivity
Log.d(TAG, "End Inflating layout")
}
private fun showSplash() {
supportActionBar?.hide()
// Inflate splash screen layout
val splashLayout =
layoutInflater.inflate(
R.layout.splash_screen,
binding.rootLayout,
false
) as LinearLayout
binding.rootLayout.addView(
splashLayout
)
}
private fun hideSplash() {
supportActionBar?.show()
binding.rootLayout.removeView(
findViewById(R.id.splash_screen)
)
}
}
Logs
2021-12-11 21:59:18.349 20681-20681/ D/LOG_TAG: Start Inflating layout
2021-12-11 21:59:18.452 20681-20707/ D/LOG_TAG: Start of delay
2021-12-11 21:59:18.476 20681-20681/ D/LOG_TAG: End Inflating layout
2021-12-11 21:59:20.457 20681-20707/ D/LOG_TAG: End of delay
Now the delay is running along with inflating the layout; the splash screen shown while it loads; and ends when the delay is over.
UPDATE 2
It's definitely not going to work: databinding = ... line takes 2.5 seconds to complete, can't add a view to "databinding.root" before it's ready. It works in the presented code because your main view is tiny.
Now try to separate inflating the layout from setContentView() in dataBinding; still both requires to be in the main thread
setContentView(R.layout.screen_splash)
CoroutineScope(Main).launch {
// Inflate main screen layout asynchronously
binding = ActivityMainBinding.inflate(layoutInflater)
delay(2500) // 2.5 sec delay of loading the mainLayout before setContentView
setContentView(binding.root)
binding.lifecycleOwner = this#MainActivity
}
Finally found the problem and, in retrospect, it was too elementary for the question:
Must assign ViewModel before lifecycleOwner
binding.viewModel = myViewModer
binding.livecycleOwner = this#MainActivity
Just changing order of these lines fixed it.

Why does the application crash when trying to select text?

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.

Another java.lang.IllegalArgumentException: parameter must be a descendant of this view

Users are getting the following exception in my app on certain phones. I tried reproducing the error myself but couldn't . I searched through stack overflow for similar problems and tried their solutions but none seem to be working.
Here are the answers I already tried:
Preventing/catching "IllegalArgumentException: parameter must be a descendant of this view" error
java.lang.IllegalArgumentException: parameter must be a descendant of this view Error
Setting the following attribute: android:windowSoftInputMode="stateHidden|adjustPan"
I have an edittext but it's outside of the expandablelistview.
I am trying to find an explanation on why this is happening and what might cause it to happen. I apologize but I can't post any code.
java.lang.IllegalArgumentException: parameter must be a descendant of
this view
at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:4568)
at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:4505)
at android.view.ViewGroup$ViewLocationHolder.init(ViewGroup.java:6743)
at android.view.ViewGroup$ViewLocationHolder.obtain(ViewGroup.java:6680)
at android.view.ViewGroup$ChildListForAccessibility.init(ViewGroup.java:6638)
at android.view.ViewGroup$ChildListForAccessibility.obtain(ViewGroup.java:6606)
at android.view.ViewGroup.addChildrenForAccessibility(ViewGroup.java:1697)
at android.view.ViewGroup.onInitializeAccessibilityNodeInfoInternal(ViewGroup.java:2525)
at android.view.View.onInitializeAccessibilityNodeInfo(View.java:5213)
at android.widget.AdapterView.onInitializeAccessibilityNodeInfo(AdapterView.java:946)
at android.widget.AbsListView.onInitializeAccessibilityNodeInfo(AbsListView.java:1449)
at android.widget.ListView.onInitializeAccessibilityNodeInfo(ListView.java:3781)
at android.widget.ExpandableListView.onInitializeAccessibilityNodeInfo(ExpandableListView.java:1348)
at android.view.View.createAccessibilityNodeInfoInternal(View.java:5174)
at android.view.View.createAccessibilityNodeInfo(View.java:5161)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:811)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:834)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:834)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:720)
at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:147)
at android.view.AccessibilityInteractionController.access$300(AccessibilityInteractionController.java:49)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:971)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(NativeStart.java)
The problem was caused by adding a wrongly inflated header to two different listviews.
I inflated a view using listViewA as the parent and adding it to listViewB also. As such:
RelativeLayout listViewHeader = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewA, false);
// Set some views
listViewA.addHeaderView(listViewHeader);
listViewB.addHeaderView(listViewHeader);
I fixed it by changing the above to the following:
RelativeLayout listViewHeaderA = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewA, false);
RelativeLayout listViewHeaderB = (RelativeLayout) inflater.inflate(R.layout.listviewheader, listViewB, false);
listViewA.addHeaderView(listViewHeaderA);
listViewB.addHeaderView(listViewHeaderB);
As for reproducing the crash, the problem happened when Google Talk Back is turned on. Here is my take on the situation: Google Talk Back does text to speech on views that are in focus (either by touch or auto-focused). When it enters a screen with multiple views requesting focus, it reads the views according to a hierarchy/order.
If you have a layout (parent) with three views (children), Google Talk Back checks how the views are arranged and then reads them accordingly. For example, in a layout with three textview lined up horizontally, Google Talk Back may read the left textview first, then the middle one, then the one on the right.
In my case, I was inflating a header view with listViewA as the parent and adding that view to both listViewA and listViewB. When listViewBgains focus and Google Talk Back tries to interpret its children, it sees the header view is not a child of the list and throws the exception. This also happens if I inflate the header view with no parents (null).
I have append on scroll listener in ScrollView
and solve problem
lst_payment_info.setOnScrollListener(new AbsListView.OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {
View currentFocus = getCurrentFocus();
if (currentFocus != null) {
currentFocus.clearFocus();
}
}
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
I was also getting the same error when Google TalkBack is turned on. In my case, I was inflating a view with the boolean attachToParent true.So by making it false worked for me.

Android: cannot update textView text dynamically from onTouchEvent

I am working on an application that allows user to drag a dot on a screen and set the values of distance for example. What I want is to have half screen for drag function and the other half with gadgets (buttons and textViews). To do so I created a class extending SurfaceView, used a bitmap "dot" and the function onTouchEvent and in my xml file I referenced like following to my view:
<test1.DragView
android:id="#+id/view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Which gives me what I want. But now I want to dynamically update the position of the dot. To do so I added setText() function for my textView in my onTouchEvent function:
#Override
public boolean onTouchEvent(MotionEvent event) {
x=(int)event.getX();
y=(int)event.getY();
bitmap =BitmapFactory.decodeResource(getResources(), R.drawable.dot);
if(x<0)
x=0;
if(x > width+(bitmap.getWidth()/2))
x=width+(bitmap.getWidth()/2);
if(y <0)
y=0;
if(y > height/2)
y=height/2;
tv=(TextView) findViewById(R.id.textView); //I declared tv in the beginning of my class
tv.setText(x);
updateBall(); //it's a function that resets the position of the dot
return true;
}
it gives me errors like
AndroidRuntime(845): FATAL EXCEPTION: main
AndroidRuntime(845): java.lang.NullPointerException
AndroidRuntime(845):
at test1.DragView.onTouchEvent(DragView.java:87)
AndroidRuntime(845):
at android.view.View.dispatchTouchEvent(View.java:5462)
AndroidRuntime(845): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1953)
I cannot use my textView in my DragView class. Is it normal? I can provide more explications if needed.
EDIT:
After using the solution of ReubenScratton I can acces my textView now but I'm getting the following error:
AndroidRuntime(672): FATAL EXCEPTION: main
AndroidRuntime(672): android.content.res.Resources$NotFoundException: String resource ID #0x109
AndroidRuntime(672): at android.content.res.Resources.getText(Resources.java:247)
AndroidRuntime(672): at android.widget.TextView.setText(TextView.java:3427)
AndroidRuntime(672): at test1.DragView.onDraw(DragView.java:73)
I am answering my own question but note that I'm just putting together the solutions given by others (ReubenScratton and lazeR) so that if someone else is having the same problem he'll find the whole solution.
So the solution: first of all instead of accessing my textView directly I had to use
tv=(TextView) ((Activity)getContext()).findViewById(R.id.textView)
because if you use
tv=(TextView)findViewById();
You're using View.findViewById() which will only search through child views.
You want to use the Activity.findViewById() ReubenScratton
And for my second problem as I was using directly an int to the setText() function it wasn't working but thanks to lazeR's comment I noticed it and found the solution. Thanks to all those who helped me :).

Categories

Resources