首页 \ 问答 \ 来自JSONParser的方法OnItemClickListener重写来自另一个活动的OnItemLongClickListener(Method OnItemClickListener from JSONParser override OnItemLongClickListener from another activity)

来自JSONParser的方法OnItemClickListener重写来自另一个活动的OnItemLongClickListener(Method OnItemClickListener from JSONParser override OnItemLongClickListener from another activity)

我正在尝试从URL收到的Json Objects创建收藏夹列表。

当我得到Json数组时,我定义了OnItemLongClickListenerOnItemClickListener方法来获得不同的东西:

  • OnItemClickListener方法必须打开另一个包含product描述的活动
  • OnItemLongClickListener方法必须将产品添加到收藏夹列表

我在MainActivity定义的方法OnItemLongClickListener是覆盖方法OnItemLongClickListener我在FragmentActivty定义的方法OnItemLongClickListener根本不起作用然后我尝试在FragmentActivity定义这两个方法,但之后两个方法根本不起作用。

有没有办法确定这个问题?

主要活动:

package com.boom.kayakapp.activities;

import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonArrayRequest;
import com.boom.kayakapp.R;
import com.boom.kayakapp.adapters.AirlinesAdapter;
import com.boom.kayakapp.controllers.AppController;
import com.boom.kayakapp.fragment.AirlinesFragment;
import com.boom.kayakapp.fragment.FavoriteFragment;
import com.boom.kayakapp.model.Airlines;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends ActionBarActivity {

        private Fragment contentFragment;
        AirlinesFragment airlinesFragment;
        FavoriteFragment favoriteFragment;

        // JSON Node names
        public static final String TAG_NAME = "name";
        public static final String TAG_PHONE = "phone";
        public static final String TAG_SITE = "site";
        public static final String TAG_LOGO = "logoURL";
        public static final String TAG_CODE = "code";

        // Log tag
        private static final String TAG = MainActivity.class.getSimpleName();

        // Airlines json url
        private static final String url = "https://www.kayak.com/h/mobileapis/directory/airlines";

        public ProgressDialog pDialog;
        public List<Airlines> airlinesList = new ArrayList<Airlines>();
        public ListView listView;
        public AirlinesAdapter adapter;

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

            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);

        listView = (ListView) findViewById(R.id.list);
        adapter = new AirlinesAdapter(this, airlinesList);
        listView.setAdapter(adapter);

        pDialog = new ProgressDialog(this);
        // Showing progress dialog before making http request
        pDialog.setMessage("Loading...");
        pDialog.show();

        // Listview on item click listener
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // getting values from selected ListItem
                String name = ((TextView) view.findViewById(R.id.name))
                        .getText().toString();
                String phone = ((TextView) view.findViewById(R.id.phone))
                        .getText().toString();
                String site = ((TextView) view.findViewById(R.id.site))
                        .getText().toString();
                String logoURL = String.valueOf(((ImageView) view.findViewById(R.id.logoURL)));

                // Starting single contact activity
                Intent in = new Intent(getApplicationContext(),
                        SingleContactActivity.class);
                in.putExtra(TAG_NAME, name);
                in.putExtra(TAG_PHONE, phone);
                in.putExtra(TAG_SITE, site);
                in.putExtra(TAG_LOGO, logoURL);
                startActivity(in);

            }
        });

        // changing action bar color
        getSupportActionBar().setBackgroundDrawable(
                new ColorDrawable(Color.parseColor("#1b1b1b")));

        // Creating volley request obj
        JsonArrayRequest airlinesReq = new JsonArrayRequest(url,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        Log.d(TAG, response.toString());
                        hidePDialog();

                        // Parsing json
                        for (int i = 0; i < response.length(); i++) {
                            try {

                                JSONObject obj = response.getJSONObject(i);
                                Airlines airlines = new Airlines();
                                airlines.setName(obj.getString("name"));
                                airlines.setLogoURL(obj.getString("logoURL"));
                                airlines.setPhone(obj.getString("phone"));
                                airlines.setCode(obj.getInt("code"));
                                airlines.setSite(obj.getString("site"));

                                // adding airlines to movies array
                                airlinesList.add(airlines);

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }

                        // notifying list adapter about data changes
                        // so that it renders the list view with updated data
                        adapter.notifyDataSetChanged();
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error: " + error.getMessage());
                hidePDialog();

            }
        });

        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(airlinesReq);

        FragmentManager fragmentManager = getSupportFragmentManager();

        /*
         * This is called when orientation is changed.
         */
        if (savedInstanceState != null) {
            if (savedInstanceState.containsKey("content")) {
                String content = savedInstanceState.getString("content");
                if (content.equals(FavoriteFragment.ARG_ITEM_ID)) {
                    if (fragmentManager.findFragmentByTag(FavoriteFragment.ARG_ITEM_ID) != null) {
                        setFragmentTitle(R.string.favorites);
                        contentFragment = fragmentManager
                                .findFragmentByTag(FavoriteFragment.ARG_ITEM_ID);
                    }
                }
            }
            if (fragmentManager.findFragmentByTag(AirlinesFragment.ARG_ITEM_ID) != null) {
                airlinesFragment = (AirlinesFragment) fragmentManager
                        .findFragmentByTag(AirlinesFragment.ARG_ITEM_ID);
                contentFragment = airlinesFragment;
            }
        } else {
            airlinesFragment = new AirlinesFragment();
//          setFragmentTitle(R.string.app_name);
            switchContent(airlinesFragment, AirlinesFragment.ARG_ITEM_ID);
        }
    }

        @Override
        public void onDestroy () {
        super.onDestroy();
        hidePDialog();
    }

    private void hidePDialog() {
        if (pDialog != null) {
            pDialog.dismiss();
            pDialog = null;
        }
    }

    @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
    protected void onSaveInstanceState(Bundle outState) {
        if (contentFragment instanceof FavoriteFragment) {
            outState.putString("content", FavoriteFragment.ARG_ITEM_ID);
        } else {
            outState.putString("content", AirlinesFragment.ARG_ITEM_ID);
        }
        super.onSaveInstanceState(outState);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_favorites:
                setFragmentTitle(R.string.favorites);
                favoriteFragment = new FavoriteFragment();
                switchContent(favoriteFragment, FavoriteFragment.ARG_ITEM_ID);

                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void switchContent(Fragment fragment, String tag) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        while (fragmentManager.popBackStackImmediate()) ;

        if (fragment != null) {
            FragmentTransaction transaction = fragmentManager
                    .beginTransaction();
            transaction.replace(R.id.content_frame, fragment, tag);
            //Only FavoriteFragment is added to the back stack.
            if (!(fragment instanceof AirlinesFragment)) {
                transaction.addToBackStack(tag);
            }
            transaction.commit();
            contentFragment = fragment;
        }
    }

    protected void setFragmentTitle(int resourseId) {
        setTitle(resourseId);
        getSupportActionBar().setTitle(resourseId);

    }

    /*
     * We call super.onBackPressed(); when the stack entry count is > 0. if it
     * is instanceof ProductListFragment or if the stack entry count is == 0, then
     * we finish the activity.
     * In other words, from ProductListFragment on back press it quits the app.
     */
    @Override
    public void onBackPressed() {
        FragmentManager fm = getSupportFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            super.onBackPressed();
        } else if (contentFragment instanceof AirlinesFragment
                || fm.getBackStackEntryCount() == 0) {
            finish();
        }
    }
}

FragmentActivity:

package com.boom.kayakapp.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import com.boom.kayakapp.R;
import com.boom.kayakapp.adapters.AirlinesAdapter;
import com.boom.kayakapp.model.Airlines;
import com.boom.kayakapp.util.SharedPreference;

import java.util.ArrayList;
import java.util.List;

public class AirlinesFragment extends Fragment implements OnItemClickListener, OnItemLongClickListener{

    public static final String ARG_ITEM_ID = "airlines_list";

    Activity activity;
    ListView airlinesListView;
    List<Airlines> airlines;
    AirlinesAdapter airlinesAdapter;

    public AirlinesFragment() {
        airlines = new ArrayList<>();

    }

    SharedPreference sharedPreference;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = getActivity();
        sharedPreference = new SharedPreference();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_list, container,
                false);
        findViewsById(view);

        airlinesAdapter = new AirlinesAdapter(activity, airlines);
        airlinesListView.setAdapter(airlinesAdapter);
        airlinesListView.setOnItemClickListener(this);
        airlinesListView.setOnItemLongClickListener(this);
        return view;
    }

    private void findViewsById(View view) {
        airlinesListView = (ListView) view.findViewById(R.id.list);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        Airlines airlines = (Airlines) parent.getItemAtPosition(position);
        Toast.makeText(activity, airlines.toString(), Toast.LENGTH_LONG).show();
    }

    @Override
    public boolean onItemLongClick(AdapterView<?> arg0, View view,
            int position, long arg3) {
        ImageView button = (ImageView) view.findViewById(R.id.favorite_button);

        String tag = button.getTag().toString();
        if (tag.equalsIgnoreCase("grey")) {
            sharedPreference.addFavorite(activity, airlines.get(position));
            Toast.makeText(activity,
                    activity.getResources().getString(R.string.add_favr),
                    Toast.LENGTH_SHORT).show();

            button.setTag("red");
            button.setImageResource(R.drawable.heart_red);
        } else {
            sharedPreference.removeFavorite(activity, airlines.get(position));
            button.setTag("grey");
            button.setImageResource(R.drawable.heart_grey);
            Toast.makeText(activity,
                    activity.getResources().getString(R.string.remove_favr),
                    Toast.LENGTH_SHORT).show();
        }

        return true;
    }

    @Override
    public void onResume() {
        getActivity().setTitle(R.string.app_name);
        super.onResume();
    }
}

I'm trying to create the favorites list from Json Objects which I received by URL.

When I got Json array, I defined methods OnItemLongClickListener and OnItemClickListener that get different things:

  • The OnItemClickListener method has to open another activity with description of product
  • The OnItemLongClickListener method has to add product to favorite list

The Problem that method OnItemClickListener which I defined in MainActivity is override method OnItemLongClickListener which I defined in FragmentActivty and the method OnItemLongClickListener doesn't work at all then I tried to define both methods in FragmentActivity but after that both methods don't work at all.

Is there any way to determine this problem?

Main Activity:

package com.boom.kayakapp.activities;

import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonArrayRequest;
import com.boom.kayakapp.R;
import com.boom.kayakapp.adapters.AirlinesAdapter;
import com.boom.kayakapp.controllers.AppController;
import com.boom.kayakapp.fragment.AirlinesFragment;
import com.boom.kayakapp.fragment.FavoriteFragment;
import com.boom.kayakapp.model.Airlines;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends ActionBarActivity {

        private Fragment contentFragment;
        AirlinesFragment airlinesFragment;
        FavoriteFragment favoriteFragment;

        // JSON Node names
        public static final String TAG_NAME = "name";
        public static final String TAG_PHONE = "phone";
        public static final String TAG_SITE = "site";
        public static final String TAG_LOGO = "logoURL";
        public static final String TAG_CODE = "code";

        // Log tag
        private static final String TAG = MainActivity.class.getSimpleName();

        // Airlines json url
        private static final String url = "https://www.kayak.com/h/mobileapis/directory/airlines";

        public ProgressDialog pDialog;
        public List<Airlines> airlinesList = new ArrayList<Airlines>();
        public ListView listView;
        public AirlinesAdapter adapter;

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

            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);

        listView = (ListView) findViewById(R.id.list);
        adapter = new AirlinesAdapter(this, airlinesList);
        listView.setAdapter(adapter);

        pDialog = new ProgressDialog(this);
        // Showing progress dialog before making http request
        pDialog.setMessage("Loading...");
        pDialog.show();

        // Listview on item click listener
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // getting values from selected ListItem
                String name = ((TextView) view.findViewById(R.id.name))
                        .getText().toString();
                String phone = ((TextView) view.findViewById(R.id.phone))
                        .getText().toString();
                String site = ((TextView) view.findViewById(R.id.site))
                        .getText().toString();
                String logoURL = String.valueOf(((ImageView) view.findViewById(R.id.logoURL)));

                // Starting single contact activity
                Intent in = new Intent(getApplicationContext(),
                        SingleContactActivity.class);
                in.putExtra(TAG_NAME, name);
                in.putExtra(TAG_PHONE, phone);
                in.putExtra(TAG_SITE, site);
                in.putExtra(TAG_LOGO, logoURL);
                startActivity(in);

            }
        });

        // changing action bar color
        getSupportActionBar().setBackgroundDrawable(
                new ColorDrawable(Color.parseColor("#1b1b1b")));

        // Creating volley request obj
        JsonArrayRequest airlinesReq = new JsonArrayRequest(url,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        Log.d(TAG, response.toString());
                        hidePDialog();

                        // Parsing json
                        for (int i = 0; i < response.length(); i++) {
                            try {

                                JSONObject obj = response.getJSONObject(i);
                                Airlines airlines = new Airlines();
                                airlines.setName(obj.getString("name"));
                                airlines.setLogoURL(obj.getString("logoURL"));
                                airlines.setPhone(obj.getString("phone"));
                                airlines.setCode(obj.getInt("code"));
                                airlines.setSite(obj.getString("site"));

                                // adding airlines to movies array
                                airlinesList.add(airlines);

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }

                        // notifying list adapter about data changes
                        // so that it renders the list view with updated data
                        adapter.notifyDataSetChanged();
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error: " + error.getMessage());
                hidePDialog();

            }
        });

        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(airlinesReq);

        FragmentManager fragmentManager = getSupportFragmentManager();

        /*
         * This is called when orientation is changed.
         */
        if (savedInstanceState != null) {
            if (savedInstanceState.containsKey("content")) {
                String content = savedInstanceState.getString("content");
                if (content.equals(FavoriteFragment.ARG_ITEM_ID)) {
                    if (fragmentManager.findFragmentByTag(FavoriteFragment.ARG_ITEM_ID) != null) {
                        setFragmentTitle(R.string.favorites);
                        contentFragment = fragmentManager
                                .findFragmentByTag(FavoriteFragment.ARG_ITEM_ID);
                    }
                }
            }
            if (fragmentManager.findFragmentByTag(AirlinesFragment.ARG_ITEM_ID) != null) {
                airlinesFragment = (AirlinesFragment) fragmentManager
                        .findFragmentByTag(AirlinesFragment.ARG_ITEM_ID);
                contentFragment = airlinesFragment;
            }
        } else {
            airlinesFragment = new AirlinesFragment();
//          setFragmentTitle(R.string.app_name);
            switchContent(airlinesFragment, AirlinesFragment.ARG_ITEM_ID);
        }
    }

        @Override
        public void onDestroy () {
        super.onDestroy();
        hidePDialog();
    }

    private void hidePDialog() {
        if (pDialog != null) {
            pDialog.dismiss();
            pDialog = null;
        }
    }

    @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
    protected void onSaveInstanceState(Bundle outState) {
        if (contentFragment instanceof FavoriteFragment) {
            outState.putString("content", FavoriteFragment.ARG_ITEM_ID);
        } else {
            outState.putString("content", AirlinesFragment.ARG_ITEM_ID);
        }
        super.onSaveInstanceState(outState);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_favorites:
                setFragmentTitle(R.string.favorites);
                favoriteFragment = new FavoriteFragment();
                switchContent(favoriteFragment, FavoriteFragment.ARG_ITEM_ID);

                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void switchContent(Fragment fragment, String tag) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        while (fragmentManager.popBackStackImmediate()) ;

        if (fragment != null) {
            FragmentTransaction transaction = fragmentManager
                    .beginTransaction();
            transaction.replace(R.id.content_frame, fragment, tag);
            //Only FavoriteFragment is added to the back stack.
            if (!(fragment instanceof AirlinesFragment)) {
                transaction.addToBackStack(tag);
            }
            transaction.commit();
            contentFragment = fragment;
        }
    }

    protected void setFragmentTitle(int resourseId) {
        setTitle(resourseId);
        getSupportActionBar().setTitle(resourseId);

    }

    /*
     * We call super.onBackPressed(); when the stack entry count is > 0. if it
     * is instanceof ProductListFragment or if the stack entry count is == 0, then
     * we finish the activity.
     * In other words, from ProductListFragment on back press it quits the app.
     */
    @Override
    public void onBackPressed() {
        FragmentManager fm = getSupportFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            super.onBackPressed();
        } else if (contentFragment instanceof AirlinesFragment
                || fm.getBackStackEntryCount() == 0) {
            finish();
        }
    }
}

FragmentActivity:

package com.boom.kayakapp.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import com.boom.kayakapp.R;
import com.boom.kayakapp.adapters.AirlinesAdapter;
import com.boom.kayakapp.model.Airlines;
import com.boom.kayakapp.util.SharedPreference;

import java.util.ArrayList;
import java.util.List;

public class AirlinesFragment extends Fragment implements OnItemClickListener, OnItemLongClickListener{

    public static final String ARG_ITEM_ID = "airlines_list";

    Activity activity;
    ListView airlinesListView;
    List<Airlines> airlines;
    AirlinesAdapter airlinesAdapter;

    public AirlinesFragment() {
        airlines = new ArrayList<>();

    }

    SharedPreference sharedPreference;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = getActivity();
        sharedPreference = new SharedPreference();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_list, container,
                false);
        findViewsById(view);

        airlinesAdapter = new AirlinesAdapter(activity, airlines);
        airlinesListView.setAdapter(airlinesAdapter);
        airlinesListView.setOnItemClickListener(this);
        airlinesListView.setOnItemLongClickListener(this);
        return view;
    }

    private void findViewsById(View view) {
        airlinesListView = (ListView) view.findViewById(R.id.list);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        Airlines airlines = (Airlines) parent.getItemAtPosition(position);
        Toast.makeText(activity, airlines.toString(), Toast.LENGTH_LONG).show();
    }

    @Override
    public boolean onItemLongClick(AdapterView<?> arg0, View view,
            int position, long arg3) {
        ImageView button = (ImageView) view.findViewById(R.id.favorite_button);

        String tag = button.getTag().toString();
        if (tag.equalsIgnoreCase("grey")) {
            sharedPreference.addFavorite(activity, airlines.get(position));
            Toast.makeText(activity,
                    activity.getResources().getString(R.string.add_favr),
                    Toast.LENGTH_SHORT).show();

            button.setTag("red");
            button.setImageResource(R.drawable.heart_red);
        } else {
            sharedPreference.removeFavorite(activity, airlines.get(position));
            button.setTag("grey");
            button.setImageResource(R.drawable.heart_grey);
            Toast.makeText(activity,
                    activity.getResources().getString(R.string.remove_favr),
                    Toast.LENGTH_SHORT).show();
        }

        return true;
    }

    @Override
    public void onResume() {
        getActivity().setTitle(R.string.app_name);
        super.onResume();
    }
}

原文:https://stackoverflow.com/questions/30983859
更新时间:2023-05-08 11:05

最满意答案

您可以在客户端计算机上安装WinDBG ,然后使用“ 映像文件执行选项 ”,并在进程启动后将WinDBG设置为打开。 然后运行崩溃过程,WinDBG将立即打开。 按g (Go)并等待进程崩溃,然后键入* .dump / mfh [dump file name] * 。 现在你有转储文件,你可以调试。


You can install WinDBG on the client machine and then use "Image File Execution Options" and set WinDBG to open once that the process has started. Then run the crashing process and WinDBG will open up immediately. press g (Go) and wait for the process to crash then type ".dump /mfh dumpFileName.dmp". Now you have dump file that you can debug.

相关问答

更多
  • 如果您刚刚安装了safari 4,请恢复为3或安装最新版本的Xcode。 希望有所帮助 If you just installed safari 4, either revert back to 3 or install the latest version of Xcode. Hope that helps
  • 您可以在客户端计算机上安装WinDBG ,然后使用“ 映像文件执行选项 ”,并在进程启动后将WinDBG设置为打开。 然后运行崩溃过程,WinDBG将立即打开。 按g (Go)并等待进程崩溃,然后键入* .dump / mfh [dump file name] * 。 现在你有转储文件,你可以调试。 You can install WinDBG on the client machine and then use "Image File Execution Options" and set WinDBG t ...
  • 我建议您使用Psscor2或Psscor4扩展(取决于您的应用程序使用的.NET版本)。 设置调试环境(安装WinDbg并复制到其文件夹Psscor文件)后,加载转储文件并加载适当版本的Psscor: .load psscor4 然后执行命令从Microsoft服务器下载符号(如果需要),确保您具有Internet连接: !symfix 从现在开始,您应该可以访问许多非常有趣的命令(查找!帮助列出它们)。 要查看每种类型的内存使用情况: !dumpheap -stat 要查看总体内存使用情况(iu表示 ...
  • 您应该使用TypedArray资源而不是String[]来存储颜色数组。 这将为您的颜色参考提供自动完成和错误检测,从而减少错误。 您可以在colors.xml文件中执行此操作,或创建单独的arrays.xml文件: @color/red @color/orange @color/yellow ...
  • 使用WinDbg附加WinDbg或启动应用程序并更改show time stamps参数: .echotimestamps 1 这会将时间戳插入到输出中,用于所有事件,例如异常,线程创建等。请参阅此msdn链接。 一旦WinDbg附加,我还会立即将日志写入磁盘: .logopen c:\temp\mylog.txt 捕获输出,这应该达到你想要的。 Attach WinDbg or start your app with WinDbg and change the show time stamps par ...
  • 你不能。 通常,属于您的进程的某些内存段可以被分页,而不是驻留在物理内存中。 这意味着使用完整内核内存转储时,无法保证重建进程地址空间。 在许多情况下,您可以从内核转储中提取有关进程的有用信息。 但是有两个限制: 正如我已经提到的,内存可以被分页。 许多WinDbg扩展不适用于内核转储。 这包括SOS,因此从内核空间调查托管进程要困难得多。 You cannot. In general, some of the memory segments that belong to your process coul ...
  • 对我来说,这个管道工作: ps -eo pid,%cpu,comm | grep java |sort -nr -k2 | head -n1 | awk '{print $1}' | xargs jstack 说明: ps -eo pid,%cpu,comm:打印具有PID CPU使用率和命令名称的所有进程 grep java:greps所有java进程 sort -nr -k2:对第二列的结果数字反向排序 head -n1:打印第一行 awk'{print $ 1}':打印第一列 xargs jstac ...
  • 如果您希望应用程序运行,这些需要在适配器中,而不是活动 courseTV = (TextView) findViewById(R.id.messageTextView); checkbox = ( CheckBox ) findViewById( R.id.checkbox ); checkbox.setOnCheckedChangeListener 这些视图都不在activity_main中 These need to be in the adapter, not the Activity if yo ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。