我正在尝试在我的片段上创建一个简单的反馈表单,但是当我滑动到联系人选项卡时,应用会停止。这是我的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 :(得分:0)
所以这是解决方案!可能会帮助某人:)
Send_feedback = (Button) rootView.findViewById(R.id.FeedbackButton);
感谢Raghunandan。