在我的日志中出错,在我的列表上刷新一些内容后,我的应用程序崩溃 Posts.java public类发布扩展活动实现OnCheckedChangeListener{ 私有静态最终字符串TAG=“POSTS”; 私有静态最终整数空\国家\代码=6; 专用静态

在我的日志中出错,在我的列表上刷新一些内容后,我的应用程序崩溃 Posts.java public类发布扩展活动实现OnCheckedChangeListener{ 私有静态最终字符串TAG=“POSTS”; 私有静态最终整数空\国家\代码=6; 专用静态,java,android,Java,Android,在我的日志中出错,在我的列表上刷新一些内容后,我的应用程序崩溃 Posts.java public类发布扩展活动实现OnCheckedChangeListener{ 私有静态最终字符串TAG=“POSTS”; 私有静态最终整数空\国家\代码=6; 专用静态最终int POST\u BACK\u BTN=7; 私有静态最终整数变化=8; 私有字符串联合国; 私有simpledapter simpleapt; 私人编辑文本帖子; 私营放射集团; 私人GPSTracker-mGPS; 私有PullTo

在我的日志中出错,在我的列表上刷新一些内容后,我的应用程序崩溃 Posts.java
public类发布扩展活动实现OnCheckedChangeListener{
私有静态最终字符串TAG=“POSTS”;
私有静态最终整数空\国家\代码=6;
专用静态最终int POST\u BACK\u BTN=7;
私有静态最终整数变化=8;
私有字符串联合国;
私有simpledapter simpleapt;
私人编辑文本帖子;
私营放射集团;
私人GPSTracker-mGPS;
私有PullToRefreshListView lv;
私有字符串initial=“Se eida”;
私有字符串码;
私有字符串unm;
私人字符串姿势;
私有字符串tmp;
私有字符串idPost;
//要显示的数据
private List postsList=new ArrayList();
JSONArray数组=null;
私有静态列表=新的ArrayList();
专用字符串pst;
私人助理基金;
私人碎片交易;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_posts);
initLocation();
如果(代码==null){
ft=getFragmentManager().beginTransaction();
//创建并显示对话框。
adf=新的AlertDialogFragments(空国家代码);
adf.show(英尺,“对话框”);
}
init();
}
私有HashMap createPost(字符串键、字符串名称){
HashMap post=新的HashMap();
post.put(键、名称);
回程站;
}
私有void initLocation(){
mGPS=新的GPSTracker(本);
最终双精度mLat=mGPS.getLatitude();
最终双精度mLong=mGPS.getLongitude();
获取地址(mLat,mLong);
}
私有无效getAddress(双mLat,双mLong){
试一试{
Geocoder gcd=新的Geocoder(这个,Locale.getDefault());
列表地址=gcd.getFromLocation(mLat,mLong,100);
如果(地址.size()>0){
地址=gcd.getFromLocation(mLat,mLong,1);
代码=地址。get(0)。getCountryCode();
}
}捕获(IOEX异常){
例如printStackTrace();
}
}
私有void init(){
此.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT\u输入\u状态\u始终\u隐藏);
Intent i=getIntent();
un=i.getStringExtra(“un”);
post=(EditText)findViewById(R.id.lbl_txt);
radGrp=(放射组)findViewById(R.id.rdg);
radGrp.setOnCheckedChangeListener(此);
//我们从布局中获取ListView组件
lv=(PullToRefreshListView)findViewById(R.id.listView);
//设置要在刷新列表时调用的侦听器。
((PullToRefreshListView)lv)
.setOnRefreshListener(新的OnRefreshListener(){
@凌驾
公共void onRefresh(){
((PullToRefreshListView)lv)
.setLastUpdated(新的SimpleDataFormat(
“dd-MM-yyy-HH:MM”)。格式(新日期());
新建GetData().execute();
}
});
simpleAdpt=新的CustomAdapter(此,postsList,
android.R.layout.simple_list_item_1,新字符串[]{“post”},
新的int[]{android.R.id.text1});
新建GetData().execute();
}
公共类CustomAdapter扩展了SimpleAdapter{
HashMap=newHashMap();
公共CustomAdapter(上下文,
列表)simpledpt
.getItem(aInfo.position-1);
String=(String)map.get(“post”);
菜单。设置标题(“选项”);
菜单。添加(1,1,1,“共享方式:”);
菜单。添加(1、2、2,“副本”);
菜单。添加(1、3、3,“删除”);
菜单。添加(1,1,1,“共享方式:”);
菜单。添加(1、2、2,“副本”);
}
//当用户在上下文菜单中选择一项时,将调用此方法
@抑制警告(“弃用”)
@凌驾
公共布尔值onContextItemSelected(MenuItem项){
int itemId=item.getItemId();
AdapterContextMenuInfo信息=(AdapterContextMenuInfo)项
.getMenuInfo();
开关(项目ID){
案例1:
//共同意向
字符串键=((TextView)info.targetView.getText().toString();
//创建发送意图
意向共享意向=新意向(android.content.Intent.ACTION\u SEND);
//设定类型
shareIntent.setType(“文本/普通”);
//添加主题
shareIntent.putExtra(android.content.Intent.EXTRA_主题,
R.string.app_name);
//构建要共享的消息体
字符串shareMessage=key.substring(0,key.length()-20)
.substring(key.indexOf(“:”)+2);
//添加消息
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,
共享消息);
//启动选择器进行共享
startActivity(Intent.createChooser(shareIntent,“共享方式:”);
打破
案例2:
//抄袭
字符串key1=((TextView)info.targetView.getText().toString();
int sdk=android.os.Build.VERSION.sdk\u int;
如果(sdkpublic class Posts extends Activity implements OnCheckedChangeListener {

private static final String TAG = "POSTS";
private static final int NULL_COUNTRY_CODE = 6;
private static final int POST_BACK_BTN = 7;
private static final int CHANGE = 8;

private String un;
private SimpleAdapter simpleAdpt;
private EditText post;
private RadioGroup radGrp;
private GPSTracker mGPS;
private PullToRefreshListView lv;
private String initial = "Se eida ";
private String code;
private String unm;
private String postui;
private String tmp;
private String idPost;

// The data to show
private List<Map<String, String>> postsList = new ArrayList<Map<String, String>>();

JSONArray array = null;

private static List<String> list = new ArrayList<String>();

private String pst;

private AlertDialogFragments adf;
private FragmentTransaction ft;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_posts);

    initLocation();

    if (code == null) {

        ft = getFragmentManager().beginTransaction();
        // Create and show the dialog.
        adf = new AlertDialogFragments(NULL_COUNTRY_CODE);
        adf.show(ft, "dialog");
    }

    init();

}

private HashMap<String, String> createPost(String key, String name) {

    HashMap<String, String> post = new HashMap<String, String>();

    post.put(key, name);

    return post;

}

private void initLocation() {

    mGPS = new GPSTracker(this);

    final double mLat = mGPS.getLatitude();
    final double mLong = mGPS.getLongitude();

    getAddress(mLat, mLong);

}

private void getAddress(double mLat, double mLong) {

    try {
        Geocoder gcd = new Geocoder(this, Locale.getDefault());
        List<Address> addresses = gcd.getFromLocation(mLat, mLong, 100);
        if (addresses.size() > 0) {

        
            addresses = gcd.getFromLocation(mLat, mLong, 1);
            code = addresses.get(0).getCountryCode();

            
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

private void init() {

    this.getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    Intent i = getIntent();

    un = i.getStringExtra("un");

    post = (EditText) findViewById(R.id.lbl_txt);

    radGrp = (RadioGroup) findViewById(R.id.rdg);
    radGrp.setOnCheckedChangeListener(this);

    // We get the ListView component from the layout

    lv = (PullToRefreshListView) findViewById(R.id.listView);

    // Set a listener to be invoked when the list should be refreshed.
    ((PullToRefreshListView) lv)
            .setOnRefreshListener(new OnRefreshListener() {
                @Override
                public void onRefresh() {
                    ((PullToRefreshListView) lv)
                            .setLastUpdated(new SimpleDateFormat(
                                    "dd-MM-yyyy HH:mm").format(new Date()));
                    new GetData().execute();
                }
            });


    simpleAdpt = new CustomAdapter(this, postsList,
            android.R.layout.simple_list_item_1, new String[] { "post" },
            new int[] { android.R.id.text1 });

    new GetData().execute();

}

public class CustomAdapter extends SimpleAdapter {
    HashMap<String, String> map = new HashMap<String, String>();

    public CustomAdapter(Context context,
            List<? extends Map<String, String>> data, int resource,
            String[] from, int[] to) {
        super(context, data, resource, from, to);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = super.getView(position, convertView, parent);

        if (row != null) {
            if (position % 2 == 0)
                row.setBackgroundResource(R.drawable.listview_selector_even);
            else
                row.setBackgroundResource(R.drawable.listview_selector_odd);
        }

        return row;
    }

}


private class GetData extends AsyncTask<String, String, String> {

    private ProgressDialog progDailog;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        progDailog = new ProgressDialog(Posts.this);
        progDailog.setMessage("Loading...");
        progDailog.setIndeterminate(false);
        progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progDailog.setCancelable(true);
        progDailog.show();
    }

    @Override
    protected String doInBackground(String... params) {

        postsList.clear();
        list.clear();

        new Thread(new Runnable() {
            public void run() {

                //getting data from server and store into results

                try {
                    array = new JSONArray(result);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                for (int i = 0; i < array.length(); i++) {

                    JSONObject row = null;
                    try {
                        row = array.getJSONObject(i);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    try {
                        unm = row.getString("Username");
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    try {
                        postui = row.getString("Post");
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    try {
                        tmp = row.getString("Timestamp");
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    try {
                        idPost = row.getString("Id");
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    pst = unm + ":\n" + postui + "\n"
                            + tmp.substring(0, tmp.length() - 2);

                    list.add(i, idPost);

                    postsList.add(createPost("post", pst));

                }

                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        lv.setSelector(R.drawable.row_pressed);
                        lv.setAdapter(simpleAdpt);
                        simpleAdpt.notifyDataSetChanged();

                        registerForContextMenu(lv);

                    }

                });

            }
        }).start();
        return null;
    }

    @Override
    protected void onPostExecute(String unused) {
        super.onPostExecute(unused);
        simpleAdpt.notifyDataSetChanged();
        progDailog.dismiss();
        ((PullToRefreshListView) lv).onRefreshComplete();
    }
}

// We want to create a context Menu when the user long click on an item
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {

    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterContextMenuInfo aInfo = (AdapterContextMenuInfo) menuInfo;

    // We know that each row in the adapter is a Map
    HashMap<?, ?> map = (HashMap<?, ?>) simpleAdpt
            .getItem(aInfo.position - 1);

    String string = (String) map.get("post");

    menu.setHeaderTitle("Options");
    
        menu.add(1, 1, 1, "Share via:");
        menu.add(1, 2, 2, "Copy");
        menu.add(1, 3, 3, "Delete");

        menu.add(1, 1, 1, "Share via:");
        menu.add(1, 2, 2, "Copy");
    

}

// This method is called when user selects an Item in the Context menu
@SuppressWarnings("deprecation")
@Override
public boolean onContextItemSelected(MenuItem item) {
    int itemId = item.getItemId();

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
            .getMenuInfo();

    switch (itemId) {
    case 1:
        // Share intent

        String key = ((TextView) info.targetView).getText().toString();

        // create the send intent
        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);

        // set the type
        shareIntent.setType("text/plain");

        // add a subject
        shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                R.string.app_name);

        // build the body of the message to be shared
        String shareMessage = key.substring(0, key.length() - 20)
                .substring(key.indexOf(":") + 2);

        // add the message
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                shareMessage);

        // start the chooser for sharing
        startActivity(Intent.createChooser(shareIntent, "Share via: "));

        break;
    case 2:
        // Copy

        String key1 = ((TextView) info.targetView).getText().toString();

        int sdk = android.os.Build.VERSION.SDK_INT;

        if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(key1.substring(0, key1.length() - 20)
                    .substring(key1.indexOf(":") + 2));

            Toast.makeText(this, "Post copied.", Toast.LENGTH_SHORT).show();

        } else {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip = android.content.ClipData
                    .newPlainText("", key1.substring(0, key1.length() - 20)
                            .substring(key1.indexOf(":") + 2));
            clipboard.setPrimaryClip(clip);

            Toast.makeText(this, "Post copied.", Toast.LENGTH_SHORT).show();

        }

        break;
    case 3:
        // Delete

        int index = info.position - 1;

                    //deletes a post
        deletePost(list.get(index), this);

        new GetData().execute();

        break;

    }

    return true;
}