public class ProductsActivity extends Activity {
DbHelper db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_products);
db = new DbHelper(getApplicationContext());
Intent intent = getIntent();
String listName = intent.getExtras().getString("position");
List<Products> listOfProducts = db.getAllProductsByList(listName);
List<String> stringListOfProducts = new ArrayList<String>();
for (int i = 0; i < listOfProducts.size(); i++)
stringListOfProducts.add(listOfProducts.get(i).getProductName());
ArrayAdapter<String> myArrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, stringListOfProducts);
ListView lv = (ListView) findViewById(R.id.listView2);
lv.setAdapter(myArrayAdapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.products, menu);
return true;
}
}
我在第37行收到错误
lv.setAdapter(myArrayAdapter);
我有另一个项目,它完成所有工作,并且工作正常!