NullPointerException
을 tv.setMovementMethod(new ScrollingMovementMethod());
에 가져 왔지만 그 이유를 알 수 없습니다! XML 파일에서 textView를 선언하고 onCreateView 내부에서 초기화했습니다. 어떤 도움을 주시면 감사하겠습니다. 여기 NullPointerException - 텍스트 뷰가있는 프래그먼트를 사용하여
public class TestConnection extends Fragment {
public TestConnection() {
}
JSONParser jParser = new JSONParser();
//button pressed to get the items
Button getAllItems;
//declare list view
TextView tv;
//Progress dialog
private ProgressDialog pDialog;
//Make an arrayList containing all items
ArrayList<HashMap<String, String>> itemsList;
//url to get items
private static String urlAllItems = "http://jamesalfei.netne.net/php/get_all_items.php";
//JSON node/tag names
private static final String TAG_SUCCESS = "success";
private static final String TAG_ITEMS = "items";
private static final String TAG_PID = "pid";
private static final String TAG_NAME = "name";
//items array
JSONArray items = null;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.sql_layout,
container, false);
getAllItems = (Button) getActivity().findViewById(R.id.SQLGetItems);
//listview
tv = (TextView) getActivity().findViewById(R.id.sqltv);
tv.setMovementMethod(new ScrollingMovementMethod());
getAllItems.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Launching All products Activity
retreiveProducts();
}
});
return view;
}
여기에 내가 어떤 나쁜 코딩 관행을 사용한 경우는 XML을
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/SQLGetItems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="@string/getSQL" />
<TextView
android:id="@+id/sqltv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/SQLGetItems"
android:text="@string/sqlLabel" />
</RelativeLayout>
사과입니다,하지만 난에 아주 새로운 해요 안드로이드 프로그래밍!
포스트와 로그 캣 오류. – Sam