findviewbyid

Error in my Fragment: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference [duplicate]

不羁的心 提交于 2021-02-11 14:53:11
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 2 years ago . I try to create a ListView which showes my Pojos called "Baustelle". I wrote a Adapter and a ViewHolder as I learned it in school but the difference is that we only did it for the MainActivity in my school. Now i tried to use a Fragment for it but I always get this Error: "Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a

ViewPager findViewById is null after screen rotation in android

风格不统一 提交于 2021-02-08 10:17:30
问题 I'm using a viewPager to display some forms. My problem is when i rotate the screen of the device and the viewPager is created again, it doesn't see the viewPager when he reaches the findViewById , it's always null . I have no idea how to handle it when rotation change. I tried the onConfigurationChange but it doesn't work, I tried to save the Id of the pager and then retrieve it using that saved id but nothing too. So I'm quite blocked now. pager = (CustomViewPager) getActivity()

findViewById not working for specific view

蹲街弑〆低调 提交于 2021-02-05 06:38:21
问题 I have an activity loaded from XML, with views having IDs as usual: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="80dp" android:layout_height="110dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <FrameLayout android:layout_width="70dp" android:layout_height="70dp" android:layout_gravity="center_horizontal" android:background="

Finding a resource given its ID - as a variable

喜你入骨 提交于 2021-01-28 19:07:05
问题 Finding a resource in your layout is easy if you know the id: LinearLayout l = FindViewById<LinearLayout>(Resource.Id.linearLayout1); but say I have String id = "linearLayout1"; How can I access the resource IDs and "find" the one I'm looking for? 回答1: You can use this: Resources#getIdentifier() String id = "linearLayout1"; int resourceId = getResources().getIdentifier(id, "id", getPackageName()); Edit: I didn't see the Xamarin tag. I am not familiar with Xamarin, but as far as I know, it

NullPointerException when accessing RelativeLayout from a custom view

别等时光非礼了梦想. 提交于 2020-01-24 12:42:07
问题 I am relatively new to Android and am completely stuck on how to access my programmatically-defined Relative Layout (defined in a fragment) in my custom View. In the fragment, this is what I have: ... @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment1, container,false); RelativeLayout rl1 = new RelativeLayout(view.getContext()); TextView tView1 = new TextView(view.getContext()); tView1

Android Activity findviewbyid() is null

做~自己de王妃 提交于 2020-01-11 08:45:31
问题 import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.Button; public class FileExplorerActivity extends Activity { public static final String TAG="ricky"; Button button; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); button = (Button) findViewById(R.id.but);<<<------------------ if(button == null) Log.d(TAG, "FileExplorerActivity: button is null"); } public FileExplorerActivity() { Log.d(TAG,