这是我的MainActivity的完整代码.如你所见,我只添加了2行:
ArrayList<String> y = null;
y.add(new String("buggy")); // When I remove this line it works
Run Code Online (Sandbox Code Playgroud)
当我注释掉y.add()时,应用程序不会崩溃.
我的问题是:为什么使用y.add()导致程序失败?
移动设备是三星Galaxy Mini S5570,运行Android 2.3.4
这是完整的代码,后面是LogCat:
package com.testbug;
import javax.*;
import java.util.*;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//
// Only these 2 lines added by me. The rest is automatically generated in Eclipse.
ArrayList<String> y = null;
y.add(new String("buggy")); // When I remove this line …Run Code Online (Sandbox Code Playgroud)