FragmentActivity에서 Fragment로 매개 변수를 전달하려고하면 Fragment의 getArguments()에서 null 포인터 예외가 발생합니다. 여기 FragmentActivity에서 Fragment로 매개 변수 전달
여기 여기 내 FragmentActivity 코드public class IndexChartActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.index_chart);
IndexFragmentActivity indexFragment =
(IndexFragmentActivity)getSupportFragmentManager().findFragmentById(R.id.index_fragment);
indexFragment.newInstance("ASPI");
}
}
인 index_chart.xml에게
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<fragment
android:id="@+id/header_fragment"
android:name="com.lk.ignitionit.cse.util.HeaderFragmentActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<fragment
android:id="@+id/index_fragment"
android:name="com.lk.ignitionit.cse.util.IndexFragmentActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<fragment
android:name="com.lk.ignitionit.cse.util.ChartFragmentActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
이며, 여기에 조각
public class IndexFragmentActivity extends Fragment {
protected ImageView ivASPI;
protected ImageView ivMPI;
protected ImageView ivSP;
protected TextView tvMain;
protected TextView tvTop;
protected TextView tvBottom;
String response = null;
String result = null;
String [] resultArr = null;
Bundle b = new Bundle();
String indexType = null;
int layout;
IndexFragmentActivity f = null;
public IndexFragmentActivity newInstance(String index) {
f = new IndexFragmentActivity();
Bundle args = new Bundle();
args.putString("indextype", index);
f.setArguments(args);
return f;
}
public String getSelectedIndex() {
return f.getArguments().getString("indextype");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if(getSelectedIndex().equals("ASPI")){
layout = R.layout.aspi_header;
}else if(getSelectedIndex().equals("MPI")){
layout = R.layout.mpi_header;
}else{
layout = R.layout.sp_header;
}
View view = inflater.inflate(layout, container, false);
tvMain = (TextView) view.findViewById(R.id.tv_main);
tvTop = (TextView) view.findViewById(R.id.tv_top);
tvBottom = (TextView) view.findViewById(R.id.tv_bottom);
new ServiceAccess().execute("");
tvMain.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
b.putString("type", "S&P SL20");
Activity activity = getActivity();
Intent intent = new Intent(activity, IndexChartActivity.class);
intent.putExtras(b);
startActivity(intent);
}
});
return view;
}
}
이고 나의 오류입니다
,622,나는 이것과 관련된 많은 stackoverflow 질문을 언급하고 주어진 예제 코드를 시도했다 http://developer.android.com/guide/components/fragments.html. 이것이 내가 알아낼 수있는 매우 기본적인 문제가 될 것으로 보인다하지만 여전히 운이
정말 ..이 다시
가이드를 보내 주셔서 감사합니다. 문제를 해결하면 작업을 수행하고 답변을 업데이트 할 것입니다. – virtualpathum