package com.prgguru.example;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;
public class MainActivity extends ActionBarActivity{
//DB Class to perform DB related operations
DBController controller = new DBController(this);
//Progress Dialog Object
ProgressDialog prgDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Get User records from SQLite DB
ArrayList<HashMap<String, String>> userList = controller.getAllUsers();
//
if(userList.size()!=0){
//Set the User Array list in ListView
ListAdapter adapter = new SimpleAdapter( MainActivity.this,userList, R.layout.view_user_entry, new String[] { "userId","userName"}, new int[] {R.id.userId, R.id.userName});
ListView myList=(ListView)findViewById(android.R.id.list);
myList.setAdapter(adapter);
//Display Sync status of SQLite DB
Toast.makeText(getApplicationContext(), controller.getSyncStatus(), Toast.LENGTH_LONG).show();
}
//Initialize Progress Dialog properties
prgDialog = new ProgressDialog(this);
prgDialog.setMessage("Synching SQLite Data with Remote MySQL DB. Please wait...");
prgDialog.setCancelable(false);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//When Sync action button is clicked
if (id == R.id.refresh) {
//Sync SQLite DB data to remote MySQL DB
syncSQLiteMySQLDB();
return true;
}
return super.onOptionsItemSelected(item);
}
//Add User method getting called on clicking (+) button
public void addUser(View view) {
Intent objIntent = new Intent(getApplicationContext(), NewUser.class);
startActivity(objIntent);
}
public void syncSQLiteMySQLDB(){
//Create AsycHttpClient object
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
ArrayList<HashMap<String, String>> userList = controller.getAllUsers();
if(userList.size()!=0){
if(controller.dbSyncCount() != 0){
prgDialog.show();
params.put("usersJSON", controller.composeJSONfromSQLite());
client.post("http://192.168.65.1/sqlitemysqlsync/insertuser.php",params ,new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
System.out.println(response);
prgDialog.hide();
try {
JSONArray arr = new JSONArray(response);
System.out.println(arr.length());
for(int i=0; i<arr.length();i++){
JSONObject obj = (JSONObject)arr.get(i);
System.out.println(obj.get("id"));
System.out.println(obj.get("status"));
controller.updateSyncStatus(obj.get("id").toString(),obj.get("status").toString());
}
Toast.makeText(getApplicationContext(), "DB Sync completed!", Toast.LENGTH_LONG).show();
} catch (JSONException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "Error Occured [Server's JSON response might be invalid]!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
@Override
public String getCharset() {
// TODO Auto-generated method stub
return super.getCharset();
}
@Override
public Header[] getRequestHeaders() {
// TODO Auto-generated method stub
return super.getRequestHeaders();
}
@Override
public URI getRequestURI() {
// TODO Auto-generated method stub
return super.getRequestURI();
}
@Override
public boolean getUseSynchronousMode() {
// TODO Auto-generated method stub
return super.getUseSynchronousMode();
}
@Override
protected void handleMessage(Message arg0) {
// TODO Auto-generated method stub
super.handleMessage(arg0);
}
@Override
protected Message obtainMessage(int responseMessageId,
Object responseMessageData) {
// TODO Auto-generated method stub
return super.obtainMessage(responseMessageId, responseMessageData);
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
super.onCancel();
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
super.onFinish();
}
@Override
public void onPostProcessResponse(
ResponseHandlerInterface instance,
HttpResponse response) {
// TODO Auto-generated method stub
super.onPostProcessResponse(instance, response);
}
@Override
public void onPreProcessResponse(
ResponseHandlerInterface instance,
HttpResponse response) {
// TODO Auto-generated method stub
super.onPreProcessResponse(instance, response);
}
@Override
public void onProgress(int bytesWritten, int totalSize) {
// TODO Auto-generated method stub
super.onProgress(bytesWritten, totalSize);
}
//@Override
public void onRetry(int retryNo) {
// TODO Auto-generated method stub
super.onRetry(retryNo);
}
@Override
public void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void postRunnable(Runnable runnable) {
// TODO Auto-generated method stub
super.postRunnable(runnable);
}
@Override
protected void sendMessage(Message msg) {
// TODO Auto-generated method stub
super.sendMessage(msg);
}
@Override
public void sendResponseMessage(HttpResponse arg0)
throws IOException {
// TODO Auto-generated method stub
super.sendResponseMessage(arg0);
}
@Override
public void setCharset(String charset) {
// TODO Auto-generated method stub
super.setCharset(charset);
}
@Override
public void setRequestHeaders(Header[] requestHeaders) {
// TODO Auto-generated method stub
super.setRequestHeaders(requestHeaders);
}
@Override
public void setRequestURI(URI requestURI) {
// TODO Auto-generated method stub
super.setRequestURI(requestURI);
}
@Override
public void setUseSynchronousMode(boolean sync) {
// TODO Auto-generated method stub
super.setUseSynchronousMode(sync);
}
@Override
protected Object clone() throws CloneNotSupportedException {
// TODO Auto-generated method stub
return super.clone();
}
@Override
public boolean equals(Object o) {
// TODO Auto-generated method stub
return super.equals(o);
}
@Override
protected void finalize() throws Throwable {
// TODO Auto-generated method stub
super.finalize();
}
@Override
public int hashCode() {
// TODO Auto-generated method stub
return super.hashCode();
}
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString();
}
@Override
public void onFailure(int statusCode, Throwable error,
String content){
// TODO Auto-generated method stub
prgDialog.hide();
if(statusCode == 404){
Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
}else if(statusCode == 500){
Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]", Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(int arg0, Header[] arg1, byte[] arg2,
Throwable arg3) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
// TODO Auto-generated method stub
}
});
}else{
Toast.makeText(getApplicationContext(), "SQLite and Remote MySQL DBs are in Sync!", Toast.LENGTH_LONG).show();
}
}else{
Toast.makeText(getApplicationContext(), "No data in SQLite DB, please do enter User name to perform Sync action", Toast.LENGTH_LONG).show();
}
}
}
编译过程中的错误有:
说明资源路径位置类型new AsyncHttpResponseHandler(){}类型的onSuccess(String)方法必须重写或实现超类型方法
IMHO,您需要使用不同的签名定义onSuccess和onFailure方法。检查您使用的是哪个版本的库,但不应该是这样的吗?
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
// Successfully got a response
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
// Response failed :(
}
错误:将字节码转换为dex时出错:原因:com . Android . dex . dex异常:多个dex文件定义了Lcom/Google/Android/GMS/internal/measurement/zza bn;:app:transformClassesWithDexForDebug失败错误:任务执行失败”:app:transformClassesWithDexForDebug。com .
我在学习android studio时遇到了这个错误: 08-20 11:56:52.192 981 5-9815/com.example.android.courtcountee1 E/AndroidRuntime:致命异常:main process:com.example.android.android.courtcountee1,PID:9815 java.lang.runtimeExcep
我添加Nuget Package Install-Package MvcSiteMapProvider.MVC4 编译器错误消息: CS1705:程序集'MvcSite Map提供者,版本=4.6.18.0,文化=中性,公共密钥令牌=1923abe4657913cc'使用'System. Web. Mvc,版本=4.0.0.0,文化=中性,公共密钥令牌=31bf3856ad364e35',其版本高
java.io.ioException:无法运行程序“/root/android/sdk/build-tools/23.0.1/aapt”:错误=2,没有这样的文件或目录
当我试图在Jetson TK1上用protoc 3.0.0 alpha 3和jdk 1.8编译Bazel 0.1.0时,我在构建Bazel工具时遇到了这个JNI链接错误。信息:Blaze版本信息:构建标签:head(@125b349)构建目标:bazel out/local_linux-fastbuild/bin/src/main/java/bazel-main_deploy。jar构建时间:20
mainactivity.java:18行代码是setContentView(r.layout.activity_main); 我该怎么解决这个?