1

我去运行我的程序,它工作正常,直到我按下回车按钮然后它停止大约 2-3 分钟然后崩溃我知道它与数组列表有关,但我该如何修复它?

以下是主要活动:

public class MainActivity extends Activity implements OnClickListener {
// Making main variables
GLSurfaceView ourSurface;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ourSurface = new GLSurfaceView(this);
    FrameLayout v =(FrameLayout)findViewById(R.id.Display);
    v.addView(ourSurface);
    ourSurface.setRenderer(new GLRenderer());

    // id'ing Buttons and EditText
    Button line = (Button) findViewById(R.id.LineVL);
    Button enter = (Button) findViewById(R.id.Enter);

    // Set on click listeners
    line.setOnClickListener(this);
    enter.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    OutPutConversion Out = new OutPutConversion();
    DrawingTools AddL = new DrawingTools();
    EditText cl = (EditText) findViewById(R.id.CL);
    TextView info = (TextView) findViewById(R.id.info);
    switch (v.getId()) {
    case R.id.LineVL:
        info.setText("Enter x,y,z For Point 1");
        break;
    case R.id.Enter:
        for(int n=0;n<=2;n++)
        switch (n) {
        case (0):
            String Input1 = cl.getText().toString();
            AddL.AddLine(Input1);
            info.setText("Enter x,y,z For Point 2");
            break;
        case (1):
            String Input2 = cl.getText().toString();
            AddL.AddLine(Input2);
            info.setText("Press Enter Again TO See Results");
            break;
        case (2):
            n = 0;
            Out.Out();
            break;
        }
    }
}

}

这是绘图工具类:

public class DrawingTools {
ArrayList<String> AL = new ArrayList<String>();

public ArrayList<String> getAL() {
    return AL;
}

public void AddLine(String Input1) {
    String[] pStrings = Input1.split(",");
    for (int i = 0; i < pStrings.length; i++) {
        AL.add(pStrings[i]);
    }

}

这是我的转换类:

public class OutPutConversion {
DrawingTools GAL = new DrawingTools();

public void Out() {
    String[] Result = GAL.getAL().toArray(new String[0]);
    float[] vertices = new float[Result.length];
    for (int i = 0; i < vertices.length; i++) {
        vertices[i] = Float.valueOf(Result[i]);

    }
}
}

最后是 Logcat:

06-14 04:25:52.362: W/dalvikvm(22810): threadid=1: thread exiting with uncaught exception (group=0x40aa41f8)
06-14 04:25:52.370: E/AndroidRuntime(22810): FATAL EXCEPTION: main
06-14 04:25:52.370: E/AndroidRuntime(22810): java.lang.OutOfMemoryError
06-14 04:25:52.370: E/AndroidRuntime(22810):    at java.util.ArrayList.add(ArrayList.java:114)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at com.example.drawingarrays.DrawingTools.AddLine(DrawingTools.java:15)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at com.example.drawingarrays.MainActivity.onClick(MainActivity.java:57)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at android.view.View.performClick(View.java:3540)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at android.view.View$PerformClick.run(View.java:14167)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at android.os.Handler.handleCallback(Handler.java:605)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at android.os.Looper.loop(Looper.java:137)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at android.app.ActivityThread.main(ActivityThread.java:4586)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at java.lang.reflect.Method.invokeNative(Native Method)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at java.lang.reflect.Method.invoke(Method.java:511)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-14 04:25:52.370: E/AndroidRuntime(22810):    at dalvik.system.NativeStart.main(Native Method)
4

0 回答 0