StormShadow
New Member
So I have the following piece of code, the code trys to add data to a database and if can't it closes the app. No matter what I do the app just closes, any advice\[code\]package net.connormccarthy.walkingdeadcharacterprofiles;import java.util.ArrayList;import android.app.Activity;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.graphics.Color;import android.graphics.Typeface;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.TableLayout;import android.widget.TableRow;import android.widget.TextView;public class rickAddNotes extends Activity{SQLiteDatabase db; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { // this try catch block returns better error reporting to the log // Android specific calls super.onCreate(savedInstanceState); setContentView(R.layout.ricknotes); Button btnLeft=(Button)findViewById(R.id.BtnRickSave); // create the database manager object //db = new MainActivity(); final Button button = (Button) findViewById(R.id.BtnRickSave); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { data(); } }); } public long data() { long d=0; //EditText edittext1=(EditText )findViewById(R.id.editText1); //String notes = edittext1.toString();try { final String Insert_Data="http://stackoverflow.com/questions/15742252/INSERT INTO Characters VALUES(2,'WOOP','5')"; db.execSQL(Insert_Data); } catch (Exception e) { System.exit(0); } return d; } public void showdata(View view) { Cursor c=db.rawQuery("SELECT * from Character WHERE character = rick", null); int count= c.getCount(); c.moveToFirst(); TableLayout tableLayout = new TableLayout(getApplicationContext()); tableLayout.setVerticalScrollBarEnabled(true); TableRow tableRow; TextView textView,textView1,textView2,textView3,textView4,textView5; tableRow = new TableRow(getApplicationContext()); textView=new TextView(getApplicationContext()); textView.setText("Firstname"); textView.setTextColor(Color.RED); textView.setTypeface(null, Typeface.BOLD); textView.setPadding(20, 20, 20, 20); tableRow.addView(textView); textView4=new TextView(getApplicationContext()); textView4.setText("LastName"); textView4.setTextColor(Color.RED); textView4.setTypeface(null, Typeface.BOLD); textView4.setPadding(20, 20, 20, 20); tableRow.addView(textView4); textView5=new TextView(getApplicationContext()); textView5.setText("Email"); textView5.setTextColor(Color.RED); textView5.setTypeface(null, Typeface.BOLD); textView5.setPadding(20, 20, 20, 20); tableRow.addView(textView5); tableLayout.addView(tableRow); for (Integer j = 0; j < count; j++) { tableRow = new TableRow(getApplicationContext()); textView1 = new TextView(getApplicationContext()); textView1.setText(c.getString(c.getColumnIndex("character"))); textView2 = new TextView(getApplicationContext()); textView2.setText(c.getString(c.getColumnIndex("notes"))); textView1.setPadding(20, 20, 20, 20); textView2.setPadding(20, 20, 20, 20); tableRow.addView(textView1); tableRow.addView(textView2); tableLayout.addView(tableRow); c.moveToNext() ; } setContentView(tableLayout); db.close(); }}\[/code\]If I dont add the exception the app just crashes. I want to ultimately get it to work with a variable I pass to it (editText1) but even when I hard code data the app just crashes or closes, depending on weather or not I add the exception.Any help is greatly appreciated.