What could be the error launching the application? An error occurred while adding a button handler. Here is the code:
package com.drusilovihi.tabbedapp_b1; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.Toast; public class TabFragment1 extends Fragment implements View.OnClickListener { private Mail m ; private ImageButton imgSend; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { m = new Mail("*************", "*******"); imgSend.findViewById(R.id.imageButton); imgSend.setOnClickListener(this); return inflater.inflate(R.layout.tab_fragment_1, container, false); } public void sendEmail(View view){ String[] toArr = {"toemail1@domain1.tld"}; // This is an array, you can add more emails, just separate them with a coma m.setTo(toArr); // load array to setTo function m.setFrom("fromEmail@domain.tld"); // who is sending the email m.setSubject("subject"); m.setBody("your message goes here"); try { //m.addAttachment("/sdcard/myPicture.jpg"); // path to file you want to attach if(m.send()) { // success Toast.makeText(getActivity(), "Email was sent successfully.", Toast.LENGTH_LONG).show(); } else { // failure Toast.makeText(getActivity() ,"Email was not sent.", Toast.LENGTH_LONG).show(); } } catch(Exception e) { // some other problem Toast.makeText(getActivity(), "There was a problem sending the email.", Toast.LENGTH_LONG).show(); } } @Override public void onClick(View v) { Toast.makeText(getActivity(), "Нажата кнопка.", Toast.LENGTH_LONG).show(); sendEmail(v); } } Glassrays:
06-17 17: 56: 10.732 13330-13330 / com.drusilovihi.tabbedapp_b1 E / AndroidRuntime: FATAL EXCEPTION: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.ImageButton.findViewById ( int) 'on a null object reference android.support.v4.app.Fragment.performCreateView (Fragment.java:1962) android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1067) android.support.v4 .app.FragmentManagerImpl.moveToState (FragmentManager.java:1248)