私は尋ねたい..私は2つのフォームを持っています、それはフォーム1とフォーム2と私はフォーム1にリストビューを持っています、私はフォーム2からデータを設定したい..だから私はそれを試すためにいくつかのダミープロジェクトを作成します..
これはform2の私のコードです:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form2);
ArrayList<MyClass> searchResults = GetSearchResults();
form1.listview.setAdapter(new MyAdapter(this, searchResults));
}
private ArrayList<MyClass> GetSearchResults(){
ArrayList<MyClass> results = new ArrayList<MyClass>();
MyClass sr = new MyClass();
sr.setJumlah_menu("Justin Schultz");
sr.setNama_menu("San Francisco, CA");
results.add(sr);
return results;
}
これは私のアダプターコードです:
public class AdapterListPemesananMenu extends BaseAdapter {
private static ArrayList<MenuInputClass> searchArrayList;
private LayoutInflater mInflater;
public AdapterListPemesananMenu(Context context, ArrayList<MenuInputClass> results) {
searchArrayList = results;
mInflater = LayoutInflater.from(context);
}
public AdapterListPemesananMenu(OnClickListener onClickListener,
ArrayList<MenuInputClass> searchResults) {
// TODO Auto-generated constructor stub
}
public int getCount() {
return searchArrayList.size();
}
public Object getItem(int position) {
return searchArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_pemesananmenu_row, null);
holder = new ViewHolder();
holder.txtName = (TextView) convertView.findViewById(R.id.txtNamaMasuk);
holder.txtCityState = (TextView) convertView
.findViewById(R.id.txtJumlahMasuk);
//holder.txtPhone = (TextView) convertView.findViewById(R.id.phone);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtName.setText(searchArrayList.get(position).getNama_menu());
holder.txtCityState.setText(searchArrayList.get(position)
.getJumlah_menu());
return convertView;
}
static class ViewHolder {
TextView txtName;
TextView txtCityState;
}
}
form1からform2に移動すると、常に強制的に閉じられます..
私のコードの何が問題なのですか?
form1で(form2から)コードを試すと、うまく機能します..
これはlogcatからのものです:
10-22 04:33:30.647: E/AndroidRuntime(15247): FATAL EXCEPTION: main
10-22 04:33:30.647: E/AndroidRuntime(15247): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aplikasipemesananmenu/list_pemesananmenu_view.SingleListView_Activity}: java.lang.NullPointerException
10-22 04:33:30.647: E/AndroidRuntime(15247): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
10-22 04:33:30.647: E/AndroidRuntime(15247): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
10-22 04:33:30.647: E/AndroidRuntime(15247): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-22 04:33:30.647: E/AndroidRuntime(15247): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
10-22 04:33:30.647: E/AndroidRuntime(15247): at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 04:33:30.647: E/AndroidRuntime(15247): at android.os.Looper.loop(Looper.java:130)
10-22 04:33:30.647: E/AndroidRuntime(15247): at android.app.ActivityThread.main(ActivityThread.java:3693)
10-22 04:33:30.647: E/AndroidRuntime(15247): at java.lang.reflect.Method.invokeNative(Native Method)
10-22 04:33:30.647: E/AndroidRuntime(15247): at java.lang.reflect.Method.invoke(Method.java:507)
10-22 04:33:30.647: E/AndroidRuntime(15247): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
10-22 04:33:30.647: E/AndroidRuntime(15247): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
10-22 04:33:30.647: E/AndroidRuntime(15247): at dalvik.system.NativeStart.main(Native Method)
10-22 04:33:30.647: E/AndroidRuntime(15247): Caused by: java.lang.NullPointerException
10-22 04:33:30.647: E/AndroidRuntime(15247): at list_pemesananmenu_view.SingleListView_Activity.onCreate(SingleListView_Activity.java:67)
10-22 04:33:30.647: E/AndroidRuntime(15247): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-22 04:33:30.647: E/AndroidRuntime(15247): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
10-22 04:33:30.647: E/AndroidRuntime(15247): ... 11 more
10-22 04:33:31.958: E/DataRouter(125): smd_file_fd = 16 and external_file_fd = 24
10-22 04:33:31.958: E/DataRouter(125): ==KDW(3)== smd_new_status = (358)
10-22 04:33:31.958: E/DataRouter(125): ==KDW(4)== smd_new_status = (320)
10-22 04:33:31.958: E/DataRouter(125): DCD pinstatus is ON
助けていただければ幸いです...