Here you go.. this is where you were making that mistake. You were trying to get the reference in you activity instead of the fragment you have defined.
Remove the buttons from your onCreate() and in you place holder fragment, add those components. That's the reason you were getting a null pointer.
NOTE: use getActivity() to reference your components in a fragment.
In you fragment you gotta make that change like this:
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment (){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
Button but1 = (Button)getActivity(). findViewById(R.id.b1);
TextView tv1 = (TextView)getActivity(). findViewById(R.id.tv1);
but1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tv1.setText("Button pressed");
}
});
}
}
Hope this helps.. :)