View still null even after inflating on OnCreateView - android

I have been struggling with the same crash for 4 hours already and I still cannot figure out the cause of it. Can any kind soul enlighten me ? I am getting this error
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
The moment it start to load my textview lbl it just crash and give me this error
Below is my code :
public class BookDoc extends Fragment {
View view;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null) {
parent.removeView(view);
}
}
try {
view = inflater.inflate(R.layout.activity_main, container, false);
} catch (InflateException e) {
}
StrictMode.ThreadPolicy policy = new StrictMode.
ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Typeface type = Typeface.createFromAsset(getActivity().getAssets(),"fonts/verdana.ttf");
TextView lbl = (TextView) view.findViewById(R.id.textViewa);
return view
}
And this is my xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f5f6f5"
>
<ScrollView
android:id="#+id/sv123"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="#+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:orientation="vertical"
android:background="#cc7781"
android:visibility="gone"
>
<TextView
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:id="#+id/tba"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:gravity="center"
android:text="View Existing Booking"
android:textSize="20dp" />
<TextView
android:id="#+id/tbb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:gravity="center"
android:text="You have already made a booking."
android:textSize="15dp" />
<TextView
android:layout_marginBottom="20dp"
android:id="#+id/tbc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:gravity="center"
android:text="Would you like to view it?"
android:textSize="15dp" />
</LinearLayout>
<LinearLayout
android:layout_below="#+id/top"
android:id="#+id/top2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:orientation="vertical" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<RelativeLayout
android:layout_below="#+id/top2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#f5f6f5"
>
<TextView
android:id="#+id/textViewa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#7D7D7D"
android:text="SELECT A NEARBY CLINIC" />
<View
android:layout_marginTop="5dp"
android:id="#+id/textView2"
android:layout_below="#+id/textViewa"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
<ListView
android:layout_marginTop="5dp"
android:layout_below="#+id/textView2"
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_marginTop="10dp"
android:id="#+id/textViewff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/listView1"
android:textColor="#e94256"
android:textSize="20dp"
android:text="View All Clinics" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>

Your view is not initialized and it is still null. Before your "if statement", initialize the view as below:
view = (View) inflater.inflate(R.layout.your_layout_file, container, false);
everything else is fine

Related

Adding Views dynamically in Linear Layout in Fragment

I am trying to add TextView to the nested linearLayout in fragmentin onCreateView, I don't know if this is the correct approach or not, new to android!
Thanks in advance
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_screen_slide_page, container, false);
List<LifeBerrysXmlParser.Item> items = (ArrayList<LifeBerrysXmlParser.Item>) getArguments().getSerializable("List");
TextView mainHeading = (TextView) rootView.findViewById(R.id.mainHeading);
ImageView mainImage = (ImageView) rootView.findViewById(R.id.articleMainImage);
LinearLayout articleLayout = (LinearLayout) rootView.findViewById(R.id.articleLayout);
TextView tev = new TextView(getActivity());
tev.setText("Hello..............");
articleLayout.addView(tev);
LifeBerrysXmlParser.Item item = items.get(getArguments().getInt("position"));
String articleMainHeading = item.mainHeading;
String articlemainImage = item.mainImage;
mainHeading.setText(articleMainHeading);
if (!articlemainImage.isEmpty()) {
Picasso.with(getContext()).load(articlemainImage).into(mainImage);
}
return rootView;
}
can anyone please help me what I am doing wrong?
here is my xml for the fragment
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="#+id/content"
android:padding="1dp"
android:layout_weight="1"
android:background="#000000"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
android:scrollIndicators="right">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/articleMainImage"
android:maxHeight="300dp"/>
<TextView
style="?android:textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightLarge"
android:layout_weight="1"
android:lineSpacingMultiplier="1.2"
android:id="#+id/mainHeading"
android:textColor="#ff6435"
android:clickable="false"
android:layout_gravity="center"
android:layout_centerInParent="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/articleLayout"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Read More"
android:textSize="15dp"
android:textStyle="bold"
android:layout_gravity="center"
android:clickable="true"
android:focusable="false"
android:gravity="center"
android:onClick="readMore"
android:padding="1dp"
android:textColor="#android:color/holo_green_light" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
You have mistake in your article layout. Your article layout has horizontal orientation, and it's child TextView has match_parent width, so when you add new child, it'll be outside the screen. Change orientation to vertical:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/articleLayout"
android:orientation="vertical"> <---- Change this line
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Read More"
android:textSize="15dp"
android:textStyle="bold"
android:layout_gravity="center"
android:clickable="true"
android:focusable="false"
android:gravity="center"
android:onClick="readMore"
android:padding="1dp"
android:textColor="#android:color/holo_green_light" />
</LinearLayout>

Getting NullPointerException when adding toolbar

Getting NullPointerExceptionwhen trying to add a toolbar which is been defined in a layout file other than main design xml file. I keep getting the following error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.support.v7.widget.Toolbar.findViewById(int)' on a null object reference
Here is my code
public class History_List_Details_Fragment extends Fragment {
Histroy_List_Model histroyListModel;
public History_List_Details_Fragment() {
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
histroyListModel = getArguments().getParcelable("historydetail");
String title=histroyListModel.getShared_title();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
super.onCreate(savedInstanceState);
View rootView = inflater.inflate(R.layout.history_list_details_fragment, container, false);
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.app_bar);
initializeListnersForToolbar(toolbar);
initializeViews(rootView);
return rootView;
}
private void initializeViews(View rootView) {
TextView titleText = (TextView) rootView.findViewById(R.id.txtTitle);
titleText.setText(histroyListModel.getShared_title());
TextView messageTExt = (TextView) rootView.findViewById(R.id.txtMessage);
titleText.setText(histroyListModel.getShared_message());
}
private void initializeListnersForToolbar(Toolbar toolbar){
((TextView) toolbar.findViewById(R.id.tool_bar_text_head)).setText(getResources().getString(R.string.friends));
((ImageView) toolbar.findViewById(R.id.tool_bar_back_arrow)).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment fragment=new History_List_Fragment();
Utilities.getInstance(getActivity()).change_HomPage_Fragment(
fragment, "History_List_Fragment", getActivity());
}
});
}
}
History_List_Details_Fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Title"
android:id="#+id/txtTitle"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Message"
android:id="#+id/txtMessage"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Duration"
android:id="#+id/txtDuration"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/lstMembers"></ListView>
</LinearLayout>
</LinearLayout>
How can I fix this error?
Add Toolbar in "history_list_details_fragment" with id "app_bar"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Title"
android:id="#+id/txtTitle"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Message"
android:id="#+id/txtMessage"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Duration"
android:id="#+id/txtDuration"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/lstMembers"></ListView>
</LinearLayout>
The error states clearly. Inside history_list_details_fragment.xml there is no Toolbar. Try to add it.
Or more probably the Toolbar is in you Activity layout, so init it inside Activity.

CheckBox OnCheckedChangeListener

I am using the checkbox of the Material Design library by navasmdc.
Now, I am trying to implement an OnCheckedChangeListener:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_review, container, false);
setHasOptionsMenu(true);
mRecyclerView = (RecyclerView) layout.findViewById(R.id.ReviewRecyclerView);
setData();
mAdapter = new MainAdapter(getActivity(), data, getIdForSelectedAnlage(), getIdForSelectedMaschine());
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mCheckBox = (com.gc.materialdesign.views.CheckBox) layout.findViewById(R.id.review_item_checkbox_simple);
mCheckBox.setOncheckListener(
new com.gc.materialdesign.views.CheckBox.OnCheckListener(){
#Override
public void onCheck(CheckBox view, boolean check) {
// Some Action
}
}
);
}
I get the following issue:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
com.gc.materialdesign.views.CheckBox.setOncheckListener(com.gc.materialdesign.views.CheckBox$OnCheckListener)'
on a null object reference
I do not understand why I get a null pointer exception ..
My XML layout of the RecyclerView Item:
<FrameLayout
android:id="#+id/anlagen_layout_container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="2dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:focusable="true"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:id="#+id/review_item_cardview_simple">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:id="#+id/review_item_imageview_simple"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Maschinenbezeichnung"
android:id="#+id/review_item_textview_title_simple"
android:layout_gravity="left|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Wert für Eigenschaft"
android:id="#+id/review_item_textview_subtitle_simple"
android:layout_gravity="left|bottom" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:orientation="vertical" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.gc.materialdesign.views.CheckBox
android:id="#+id/review_item_checkbox_simple"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#1E88E5"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</FrameLayout>

How to remove main activities buttons from the fragment with the codes in android?

How to remove main activities buttons from the fragment with the codes in android?
There are a few buttons in activity_main.xml. I want to access and remove a button from the fragment class. Is this posssible and how?
main_activ.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/paper"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:orientation="horizontal" >
<Button
android:id="#+id/butBack"
android:layout_width="wrap_content"
android:layout_height="60.0dip"
android:layout_gravity="fill"
android:layout_weight="0.5"
android:text=".."
android:textColor="#ffffffff"
android:textSize="16.0sp"
android:background="#drawable/button_style"
android:textStyle="bold" />
<Button
android:id="#+id/butMain"
android:layout_width="wrap_content"
android:layout_height="60.0dip"
android:layout_gravity="fill"
android:layout_marginLeft="2dp"
android:layout_weight="0.5"
android:text="..."
android:textColor="#ffffffff"
android:textSize="16.0sp"
android:background="#drawable/button_style"
android:textStyle="bold" />
<Button
android:id="#+id/butNext"
android:layout_width="wrap_content"
android:layout_height="60.0dip"
android:layout_gravity="fill"
android:layout_marginLeft="2dp"
android:layout_weight="0.5"
android:text=".."
android:textColor="#ffffffff"
android:textSize="16.0sp"
android:background="#drawable/button_style"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
My fragment
public class Frag_Menu extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.frag_menu, container, false);
return view;
}
public void onActivityCreated(Bundle savedInstanceState) {
ViewGroup layout = (ViewGroup) getActivity().findViewById(R.id.butBack).getParent();
if(null!=layout)
layout.removeView(layout);
};
public static android.support.v4.app.Fragment newInstance(String string) {
return null;
}
}
You can use getActivity().findViewById() to get your Button from the fragment class in onActivityCreated().
View button = getActivity().findViewById(R.id.butBack);
if (button != null && button.getParent() != null) {
((ViewGroup)button.getParent()).removeView(button);
}

It show the java.lang.NullPointerException when set the framelayout to VISIBLE in android

I detect the WIFI connect , when WIFI connect is break.
It will show the framelayout on the top of all widgets.
public class MjpegPlayerFragment extends Fragment {
public static FrameLayout reconnect_layout;
private class GetTimeStamp extends AsyncTask<URL, Integer, String> {
protected void onPostExecute(String result) {
Activity activity = getActivity() ;
if (activity != null) {
reconnect_fragment();
}
super.onPostExecute(result) ;
}
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.preview_player, container, false) ;
reconnect_layout = (FrameLayout) getActivity().findViewById(R.id.reconnect_layout);
return view ;
}
public static void reconnect_fragment() {
reconnect_layout.setVisibility(View.VISIBLE);
}
And the code of xml is like the following:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/reconnect_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
android:background="#454749">
<RelativeLayout
android:id="#+id/layout_imgbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_above="#+id/bottom_buttonlayout"
android:layout_below="#+id/top_buttonlayout"
android:orientation="horizontal" >
<ImageView
android:id="#+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/connect"
android:layout_centerVertical="true"
android:background="#drawable/phone"/>
<ImageView
android:id="#+id/connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/break1"/>
<ImageView
android:id="#+id/break_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/connect"
android:layout_centerVertical="true"
android:background="#drawable/camera_break"
/>
</RelativeLayout>
<LinearLayout
android:id="#+id/Reconnect_button_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_below="#+id/layout_break_text"
android:layout_centerInParent="true"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/Imgbtn_reconnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:background="#00000000"
android:src="#drawable/reconnect" />
</LinearLayout>
<FrameLayout
android:id="#+id/player_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#+id/player_surface_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" >
<SurfaceView
android:id="#+id/player_surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
</FrameLayout>
</FrameLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/top_buttonlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#444444" >
<ImageView
android:id="#+id/imageBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#drawable/logo"
/>
<ImageButton
android:id="#+id/SettingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:background="#drawable/parmeter_setting" />
<ImageButton
android:id="#+id/FileSavebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:scaleType="fitXY"
android:background="#drawable/save_in_camera" />
</LinearLayout>
</RelativeLayout>
When it call the reconnect_fragment(); it show the java.lang.NullPointerException at reconnect_layout.setVisibility(View.VISIBLE);
Does there has any wrong ?
How to solve this problem ?
As you said in your comment framelayout is in fragment layout
So Change to
reconnect_layout = (FrameLayout) view.findViewById(R.id.reconnect_layout);
If it is in activity xml you use getActivity().findViewById
replace
reconnect_layout = (FrameLayout) getActivity().findViewById(R.id.reconnect_layout);
with
reconnect_layout = (FrameLayout) view.findViewById(R.id.reconnect_layout);

Categories

Resources