Matthew1246
Lurker
Program crashes when tries to load suggestions. Please help.
Code:
package com.Hello;
import android.app.Activity;
import android.widget.Button;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.CheckBox;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.Window;
import android.widget.ListView;
import android.widget.TextView;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.content.Context;
import android.util.Log;
import android.database.Cursor;
import android.widget.SimpleCursorAdapter;
import java.io.*;
import android.widget.*;
public class HelloWorld3 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout Max = new LinearLayout(this);
Max.setOrientation(LinearLayout.VERTICAL);
LinearLayout miniMe = new LinearLayout(this);
final TextView tv = new TextView(this);
String[] strings = new String[]{"apple","banana"};
TextView tv1 = new TextView(this);
final AutoCompleteTextView te = new AutoCompleteTextView(this);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,tv1.getId(),strings);
te.setAdapter(arrayAdapter);
te.setWidth(250);
CheckBox cb = new CheckBox(this);
miniMe.addView(te);
miniMe.addView(cb);
Max.addView(miniMe);
Max.addView(tv);
cb.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
PrintStream out = null;
try
{
out = new PrintStream(openFileOutput("helloworld.txt", Context.MODE_APPEND));
}
catch(FileNotFoundException ex)
{
tv.append("Output" +ex.toString());
}
String line = te.getText().toString();
tv.append(line + "\n");
te.setText("");
out.append(line + "\n");
out.close();
}
});
int count = 1;
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(openFileInput("helloworld.txt")));
while(true)
{
String line = in.readLine();
if(line == null)
{
break;
}
tv.append(line + "\n");
}
in.close();
}
catch(FileNotFoundException ex)
{
if(count >= 2)
{
tv.append(ex.toString());
}
else
{
count++;
}
}
catch(IOException ex)
{
if(count >= 2)
{
tv.append(ex.toString());
}
else
{
count++;
}
}
setContentView(Max);
}
}