I have both classes below: DataLoad.java
public class DataLoad extends Activity {
SQLiteDatabase mDatabase;
Session session;
public static String jsonString = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.data_load_activity);
// OBJECTS
CRUD crud = new CRUD(getApplicationContext());
session = new Session(getApplicationContext());
crud.destroy();
if(!Functions.DatabaseExists(getApplicationContext().getDatabasePath(Config.DATABASE_NAME).toString())){
try {
crud.open();
getAppData();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public void getAppData(){
Webservices webservice = new Webservices(getApplicationContext());
webservice.execute();
}
public void Builder(){
session.insert("json_content", jsonString);
Intent intent = new Intent(DataLoad.this, Login.class);
startActivity(intent);
}
}
Webservices.java
public class Webservices extends AsyncTask<String,String,String> {
Context mContext;
ProgressDialog progressDialog;
public Webservices(Context context){
mContext = context;
}
@Override
protected String doInBackground(String... string) {
String RETRIEVED_CONTENT = "";
InputStream inputStream;
try {
// New HTTP Object
HttpClient httpclient = new DefaultHttpClient();
// New POST Object
HttpPost httppost = new HttpPost(Config.DOMAIN+Config.WEBSERVICE_PATH+Config.DATA_FILE);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line;
while((line = reader.readLine()) != null){
sb.append(line).append("\n");
}
RETRIEVED_CONTENT = sb.toString();
} catch (Exception e) {
Log.e("HTTP", "Error in http connection " + e.toString());
}
DataLoad.jsonString = RETRIEVED_CONTENT;
return RETRIEVED_CONTENT;
}
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(mContext, "Por favor aguarde...", "Validando dados de login.", true);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
DataLoad dataLoad = new DataLoad(mContext);
dataLoad.Builder();
}
}
I need to be able to execute the Builder
function of the DataLoad class within the onPostExecute
method but I am getting the following error:
7247-7247/pt.project01 E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{pt.project01/pt.project01.ui.activities.DataLoad}: java.lang.InstantiationException: can't instantiate class pt.cartuxa_pro_gold.ui.activities.DataLoad; no empty constructor
How can I manipulate the onPostExecute
method so that after running I was able to call other functions within the class that activated it?