InflateException错误行40

时间:2014-03-06 08:30:19

标签: android

因此,每当我从一个活动切换到另一个将ListView作为组件的活动时,我会在尝试加载列表视图时不断获得InflateException。这里是列表视图的活动代码:

public class UserIndexActivity extends Activity {

    private AccountDAO accountDataSource;
    public static final String PREFS_NAME = "MyPreferenceFile";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_index);

        accountDataSource = new AccountDAO(this);
        accountDataSource.open();

        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
        String userID = settings.getString("userid", "Default");
        List<Account> accListQuery = accountDataSource.getAllAccounts(userID);
        List<String> list = new ArrayList<String>();
        for(Account a : accListQuery)
            list.add("Account Name: " + a.getDisplayName() + " \t Balance: " + a.getBalance() + " \t Interest Rate: " + a.getInterestRate());
//      ArrayList<String> list = new ArrayList<String>();
//      list.add("ASdfasdfasfd");
//      list.add("asdfasfas");
//      List<String> list = (ArrayList)accountDataSource.getAllAccounts(userID);
        ListView listView = (ListView)findViewById( R.id.listview);
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, list );
        listView.setAdapter( adapter );
        listView.setClickable(true);
        final ListView tempView = listView;
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                 Account o = (Account)tempView.getItemAtPosition(position);
                 Intent intent = new Intent(UserIndexActivity.this,TransactionActivity.class);
                 startActivity(intent);
             }

        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.user_index, menu);
        return true;
    }

    public void addAccount(View view){
        Intent intent = new Intent(this, AddAccountActivity.class);
        startActivity(intent);
    }
}

我该如何修复此错误?

0 个答案:

没有答案