1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

help autocompletetextview crashes


Last Updated:

  1. Matthew1246

    Matthew1246 New Member This Topic's Starter

    Joined:
    Dec 9, 2010
    Messages:
    1
    Likes Received:
    0
    Program crashes when tries to load suggestions. Please help.
    Code (Text):
    1. package com.Hello;
    2.  
    3. import android.app.Activity;
    4. import android.widget.Button;
    5. import android.os.Bundle;
    6. import android.widget.EditText;
    7. import android.widget.LinearLayout;
    8. import android.widget.CheckBox;
    9. import android.view.View.OnClickListener;
    10. import android.view.View;
    11. import android.view.Window;
    12. import android.widget.ListView;
    13. import android.widget.TextView;
    14. import android.database.sqlite.SQLiteOpenHelper;
    15. import android.database.sqlite.SQLiteDatabase;
    16. import android.content.Context;
    17. import android.util.Log;
    18. import android.database.Cursor;
    19. import android.widget.SimpleCursorAdapter;
    20. import java.io.*;
    21. import android.widget.*;
    22. public class HelloWorld3 extends Activity {
    23.     /** Called when the activity is first created. */
    24.     @Override
    25.     public void onCreate(Bundle savedInstanceState) {
    26.         super.onCreate(savedInstanceState);
    27.         LinearLayout Max = new LinearLayout(this);
    28.         Max.setOrientation(LinearLayout.VERTICAL);
    29.         LinearLayout miniMe = new LinearLayout(this);
    30.        
    31.         final TextView tv = new TextView(this);
    32.         String[] strings = new String[]{"apple","banana"};
    33.         TextView tv1 = new TextView(this);
    34.         final AutoCompleteTextView te = new AutoCompleteTextView(this);
    35.         ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,tv1.getId(),strings);
    36.         te.setAdapter(arrayAdapter);
    37.         te.setWidth(250);
    38.         CheckBox cb = new CheckBox(this);
    39.        
    40.        
    41.         miniMe.addView(te);
    42.         miniMe.addView(cb);
    43.         Max.addView(miniMe);
    44.         Max.addView(tv);
    45.        
    46.         cb.setOnClickListener(new OnClickListener()
    47.         {
    48.             public void onClick(View v)
    49.             {
    50.                 PrintStream out = null;
    51.                 try
    52.                 {
    53.                     out = new PrintStream(openFileOutput("helloworld.txt", Context.MODE_APPEND));
    54.                 }
    55.                 catch(FileNotFoundException ex)
    56.                 {
    57.                     tv.append("Output" +ex.toString());
    58.                 }
    59.                 String line = te.getText().toString();
    60.                 tv.append(line + "\n");
    61.                 te.setText("");
    62.                 out.append(line + "\n");
    63.                 out.close();
    64.             }
    65.         });
    66.         int count = 1;
    67.         try
    68.         {
    69.             BufferedReader in = new BufferedReader(new InputStreamReader(openFileInput("helloworld.txt")));
    70.             while(true)
    71.             {
    72.                     String line = in.readLine();
    73.                     if(line == null)
    74.                     {
    75.                         break;
    76.                     }
    77.                     tv.append(line + "\n");
    78.             }
    79.             in.close();
    80.         }
    81.         catch(FileNotFoundException ex)
    82.         {
    83.             if(count >= 2)
    84.             {
    85.                 tv.append(ex.toString());
    86.             }
    87.             else
    88.             {
    89.                 count++;
    90.             }
    91.         }
    92.         catch(IOException ex)
    93.         {
    94.             if(count >= 2)
    95.             {
    96.                 tv.append(ex.toString());
    97.             }
    98.             else
    99.             {
    100.                 count++;
    101.             }
    102.         }
    103.         setContentView(Max);
    104.     }
    105. }
     

    Advertisement
  2. rf2244

    rf2244 New Member

    Joined:
    Apr 15, 2015
    Messages:
    1
    Likes Received:
    0
    Hi did you ever get this program working? I also want to use AutoCompleteTextview without any XML usage.
    Thanks... rezaf_2006 Atttt oohay
     

Share This Page

Loading...