All Questions

779
votes
30answers
421785 views

findViewById in Fragment

I am trying to create an ImageView in a Fragment which will refer to the ImageView element which I have created in the XML for the Fragment. However, the findViewById method only works if I extend an ...
35
votes
9answers
43481 views

Null pointer Exception - findViewById()

Can anyone help me to find out what can be the issue with this program. In the onCreate() method the findViewById() returns null for all ids and this causes a null pointer exception later. I can not f...
163
votes
3answers
121119 views

How can I assign an ID to a view programmatically?

In an XML file, we can assign an ID to a view like android:id="@+id/something" and then call findViewById(), but when creating a view programmatically, how do I assign an ID? I think setId() is not t...
1
votes
4answers
806 views

Why Android app crashes for initializing variable with findViewById(R.id.******) at the beginning of the class?

I was just testing input/output, there was no special purpose, this is the last code that had run successfully: public class MainActivity extends AppCompatActivity { /* EditText username = (EditTex...
6
votes
1answers
22479 views

Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference

When my SplashActivity opens the LoginActivity my app crashes. The following is my SplashActivity.java: package com.example.android.appName; import android.content.Intent; import android.os.Bundle;...
62
votes
4answers
8371 views

No need to cast the result of findViewById?

Recently i found that AndroidStudio reminds me to remove some class cast. I remember that in the old time, we have to cast the result of findViewById, but now it's not necessary. The result of findV...
19
votes
2answers
3199 views

Class cast exception to same class on Android

I'm having a strange problem with ClassCastException on Android. One class cannot be casted to the same class: java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.ClassCastE...
4
votes
2answers
13053 views

adding touch listener for liner layout filled with buttons

I added a touch event to a linear layout to respond to swipe gestures, and it works well. However, when i add buttons to the layout, the parent liner layout is ignored. How should I prevent this from...
3
votes
5answers
3782 views

Cast result findViewById android method

Why do we always have to cast the value returned by the method findViewById(id) ? The method already returns a view, as I've seen in google reference : http://developer.android.com/reference/android/...
10
votes
4answers
26428 views

findViewById() returns null - tried EVERYTHING

I give up... not even my professor knows why this is happening. The problem is: No matter where or how I call for this layout's components, they always return null. LAYOUT: search_layout. 2 EdiTe...

Previous Next