Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6883787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:25:35+00:00 2026-05-27T05:25:35+00:00

all I have an error begin thrown up when I am running my code.

  • 0

all I have an error begin thrown up when I am running my code. I have no idea what the issue could be cause I have been told in theory it should work and eclipse does not seem to detect any errors with coding. Any help on how to improve the code or how to solve the runtime error would be much appreciated.

The code is the following:

public class DatabaseActivity extends Activity {
/** Called when the activity is first created. */

public DBAdapter
DBAdapter =new DBAdapter(this);

TextView txt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create a crude view - this should really be set via the layout resources  
// but since its an example saves declaring them in the XML.  
LinearLayout rootLayout = new LinearLayout(getApplicationContext());  
txt = new TextView(getApplicationContext());  
rootLayout.addView(txt);  
setContentView(rootLayout);  

// Set the text and call the connect function.  
txt.setText("Connecting..."); 
//call the method to run the data retreival
txt.setText(getServerData(KEY_153)); 

}

public static final String KEY_153 = "http://xxxx.xxxx.com/api/execute.php";


private String getServerData(String returnString) {

InputStream is = null;

String result = "";
//the train line to send
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("gender","M"));

//http post
try{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(KEY_153);
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();

}catch(Exception e){
        Log.e("log_tag", "Error in http connection "+e.toString());
}

//convert response to string
try{
        BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
        }
        is.close();
        result=sb.toString();
}catch(Exception e){
        Log.e("log_tag", "Error converting result "+e.toString());
}

//parse json data
try{
        JSONArray jArray = new JSONArray(result);
        for(int i=0;i<jArray.length();i++){
                JSONObject json_data = jArray.getJSONObject(i);
                DBAdapter.insertPerson(json_data.getString("id"),
                                json_data.getString("firstname"),
                                json_data.getString("surname"),
                                json_data.getString("gender"),
                                json_data.getString("age"),
                                json_data.getString("race"),
                                json_data.getString("height"),
                                json_data.getString("weight"));

                //Get an output to the screen
                returnString += "\n\t" + jArray.getJSONObject(i); 
        }
}catch(JSONException e){
        Log.e("log_tag", "Error parsing data "+e.toString());
}
return returnString; 
}    

}

The DPAdapter is:

public class DBAdapter{
public static final String KEY_ID = "id";
public static final String KEY_FIRSTNAME = "firstname";
public static final String KEY_SURNAME = "surname";
public static final String KEY_GENDER = "gender";
public static final String KEY_AGE = "age";
public static final String KEY_RACE = "race";
public static final String KEY_HEIGHT = "height";
public static final String KEY_WEIGHT = "weight";
private static final String TAG = "DBAdapter";

private static final String DATABASE_NAME = "survey";
private static final String DATABASE_TABLE = "people";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CREATE =
    "create table titles (id integer primary key, "
    + "firstname text not null,"
    + "surname text not null,"
    + "gender text not null,"
    + "age text not null,"
    + "race text not null,"
    + "height text not null,"
    + "weight text not null);";

private final Context context; 

private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter(Context ctx)
  {
      this.context = ctx;
      DBHelper = new DatabaseHelper(context);
      this.db=DBHelper.getWritableDatabase();
  }

private static class DatabaseHelper extends SQLiteOpenHelper 
{
    DatabaseHelper(Context context) 
    {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db) 
    {
        db.execSQL(DATABASE_CREATE);        }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, 
    int newVersion) 
    {
        Log.w(TAG, "Upgrading database from version " + oldVersion 
                + " to "
                + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS titles");
        onCreate(db);
    }
}    

//---opens the database---
public DBAdapter open() throws SQLException 
{
    db = DBHelper.getWritableDatabase();
    return this;
}
//---closes the database---    
public void close() 
{
    DBHelper.close();
}

//---insert a title into the database---
public long insertPerson(String id, String firstname, String surname, String gender, String age, String race, String height, String weight) 
{
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_ID, id);
    initialValues.put(KEY_FIRSTNAME, firstname);
    initialValues.put(KEY_SURNAME, surname);
    initialValues.put(KEY_GENDER, gender);
    initialValues.put(KEY_AGE, age);
    initialValues.put(KEY_RACE, race);
    initialValues.put(KEY_HEIGHT, height);
    initialValues.put(KEY_WEIGHT, weight);
    return db.insert(DATABASE_TABLE, null, initialValues);
}
}

Error Log:

Database [Android Application]  
DalvikVM[localhost:9115]    
    Thread [<1> main] (Suspended (exception RuntimeException))  
        ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1680    
        ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1784 
        ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 123   
        ActivityThread$H.handleMessage(Message) line: 939   
        ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
        Looper.loop() line: 130 
        ActivityThread.main(String[]) line: 3835    
        Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
        Method.invoke(Object, Object...) line: 507  
        ZygoteInit$MethodAndArgsCaller.run() line: 847  
        ZygoteInit.main(String[]) line: 605 
        NativeStart.main(String[]) line: not available [native method]  
    Thread [<8> Binder Thread #2] (Running) 
    Thread [<7> Binder Thread #1] (Running) 

Most of the above has shown that the source cannot be found using debug.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:25:36+00:00Added an answer on May 27, 2026 at 5:25 am

    You’re doing a network request on the main thread, which will cause ANRs & you’re writing to persistent storage for each person in the JSON, which could add up to a long operation. The network request should be done on a separate thread, and you should be able to compile the people into one cursor to write into the database all at once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Advance New Year Wishes to All. I have an error log file with the
I have a strange error where my jquery ajax request doesn't submit all the
We have multiple vb projects.We want to put error handlers in all functions, and
I keep getting this error all over the place where I only have jquery
Rails displays all validation error messages associated with a given field. If I have
it is very strange, because this error doesn't happen all the time... I have
I have a custom error handler attached to E_ALL PHP errors. In an external
Hi on our dev environment we have show all errors, warnings and notices. I'm
I have three classes that all have a static function called 'create'. I would
I'm sure we all have received the wonderfully vague Object reference not set to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.