2014-01-29 2 views
0

Я пытаюсь создать простую форму обратной связи на моем фрагменте, но приложение останавливается, когда я сажусь на вкладку контактов. вот мой contactfragment.java код:Форма контакта на фрагменте не работает

package me.hicham.resume; 

import android.support.v4.app.Fragment; 
import android.content.Intent; 
import android.graphics.Typeface; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 
import android.widget.Toast; 
import me.hicham.resume.R; 

public class ContactFragment extends Fragment { 

public ContactFragment(){} 
Button Send_feedback; 
EditText name,email,subject,message; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
    Bundle savedInstanceState) { 

    View rootView = inflater.inflate(R.layout.fragment_contact, container, false); 

    Send_feedback = (Button) getView().findViewById(R.id.FeedbackButton); 
    name = (EditText) getView().findViewById(R.id.NameText); 
    email = (EditText) getView().findViewById(R.id.EmailText); 
    subject = (EditText) getView().findViewById(R.id.subjecttext); 
    message = (EditText) getView().findViewById(R.id.messagetext); 

    Send_feedback.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      String b_name = name.getText().toString(); 
      String b_email = email.getText().toString(); 
      String b_subject = subject.getText().toString(); 
      String b_message = message.getText().toString(); 

      Intent email = new Intent(Intent.ACTION_SEND); 
      email.putExtra(Intent.EXTRA_TEXT,b_name); 
      email.putExtra(Intent.EXTRA_EMAIL, new String[]{ b_email}); 
      email.putExtra(Intent.EXTRA_SUBJECT, b_subject); 
      email.putExtra(Intent.EXTRA_TEXT, b_message); 

      email.setType("message/rfc822"); 
      startActivity(Intent.createChooser(email, "Choose an Email client :")); 

     } 
    }); 
    return rootView; 
} 

public void onViewCreated (View view, Bundle savedInstanceState){ 
    Typeface opensans = Typeface.createFromAsset(getActivity().getAssets(), "fonts/OpenSans-Light.ttf"); 


    TextView contact1 = (TextView) getView().findViewById(R.id.contact1); 
    contact1.setTypeface(opensans); 
    contact1.setText("Let's Talk !"); 

    TextView contacttext = (TextView) getView().findViewById(R.id.contacttext); 
    contacttext.setTypeface(opensans); 
    contacttext.setText("\" If you want to discuss a possible project, know more about me, or just have a chitchat :) please get in touch.\""); 

    EditText nametext = (EditText) getView().findViewById(R.id.NameText); 
    nametext.setTypeface(opensans); 

    EditText emailtext = (EditText) getView().findViewById(R.id.EmailText); 
    emailtext.setTypeface(opensans); 

    EditText messagetext = (EditText) getView().findViewById(R.id.messagetext); 
    messagetext.setTypeface(opensans); 

    EditText subjecttext = (EditText) getView().findViewById(R.id.subjecttext); 
    subjecttext.setTypeface(opensans); 

} 

} 

Вот что говорит Logcat:

01-29 20:27:07.330: E/AndroidRuntime(20311): at me.hicham.resume.ContactFragment.onCreateView(ContactFragment.java:29) 

Может кто-нибудь пожалуйста, скажите мне, где проблема? Благодарю.

+0

'Send_feedback = (кнопка) rootView.findViewById (R.id.FeedbackButton);' тот же для других просмотров – Raghunandan

+0

Это решило мою проблему! Спасибо @Raghunandan BTW, это нормально, что у моего приложения нет функции onCreate()? – RidRoid

ответ

0

Так вот решение! может помочь кому-то :)

Send_feedback = (Button) rootView.findViewById(R.id.FeedbackButton); 

благодаря Рагхунандану.

Смежные вопросы