Android - 如何检测崩溃我的应用程序?

时间:2014-09-04 12:48:30

标签: java android

所以我有这个问题,我认为代码应该可行,但它没有。它在应用程序启动时崩溃了。 Logcat似乎没有帮助,所以如何检测崩溃我的应用程序?  如果有人想检查错误或其他什么,这是我的应用程序的代码 http://www23.zippyshare.com/v/472319/file.html

这是MainActivity.java

package com.example.sqllite;

import java.util.ArrayList;

import com.example.kontaktysqllite.R;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends ListActivity{

private ProgressDialog m_ProgressDialog = null; 
private ArrayList<Order> m_orders = null;
private OrderAdapter m_adapter;
private Runnable viewOrders;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    m_orders = new ArrayList<Order>();
    this.m_adapter = new OrderAdapter(this, R.layout.row, m_orders);
    setListAdapter(this.m_adapter);

    viewOrders = new Runnable(){

        @Override
        public void run() {
            getOrders();
        }
    };
    Thread thread =  new Thread(null, viewOrders, "MagentoBackground");
    thread.start();
    m_ProgressDialog = ProgressDialog.show(MainActivity.this,    
          "Please wait...", "Retrieving data ...", true);
}
private Runnable returnRes = new Runnable() {
    @Override
    public void run() {
        if(m_orders != null && m_orders.size() > 0){
            m_adapter.notifyDataSetChanged();
            for(int i=0;i<m_orders.size();i++)
            m_adapter.add(m_orders.get(i));
        }
        m_ProgressDialog.dismiss();
        m_adapter.notifyDataSetChanged();
    }
};
private void getOrders(){
      try{
          final ZarzadcaBazy zb = new ZarzadcaBazy(this);


          m_orders = new ArrayList<Order>();
          Cursor k = zb.dajWszystkie();
          while (k.moveToNext()) {
              String message = k.getString(1);
              Order order = new Order();
              order.setOrderLink(message);
              order.setOrderName("szablon");
              m_orders.add(order);
              Log.i("ARRAY", ""+ m_orders.size());
          }


        } catch (Exception e) { 
          Log.e("BACKGROUND_PROC", e.getMessage());
        }
        runOnUiThread(returnRes);
    }
private class OrderAdapter extends ArrayAdapter<Order> {

    private ArrayList<Order> items;

    public OrderAdapter(Context context, int textViewResourceId, ArrayList<Order> items) {
            super(context, textViewResourceId, items);
            this.items = items;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
            View v = convertView;
            if (v == null)
            {
                LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.row, null);
            }
            Order o = items.get(position);
            if (o != null)
            {
                    TextView name = (TextView) v.findViewById(R.id.row_textView);
                    ImageView img = (ImageView)findViewById(R.id.row_imageview);
                    if (name != null) 
                    {
                        name.setText("Name: "+o.getOrderName());                            
                    }

                    img.setOnClickListener(new View.OnClickListener()
                    {
                        public void onClick(View view)
                        {       
                            Intent intent = new Intent(MainActivity.this, Activity2.class);
                            intent.putExtra("urlString", "https://beta2.createer.com/Action/Show/777203e8-5b53-462d-863b-c4e10a3abd5b/");
                            startActivity(intent);
                        }
                    });
            }

            return v;
    }
}
}

logcat的:

09-04 14:56:37.244: I/Process(579): Sending signal. PID: 579 SIG: 9
09-04 14:56:37.374: W/ApplicationPackageManager(868): getCSCPackageItemText()
09-04 14:56:37.424: D/AbsListView(868): Get MotionRecognitionManager
09-04 14:56:37.444: D/AbsListView(868): onVisibilityChanged() is called, visibility : 8
09-04 14:56:37.444: D/AbsListView(868): unregisterIRListener() is called 
09-04 14:56:37.464: I/ARRAY(868): 1
09-04 14:56:37.464: I/ARRAY(868): 2
09-04 14:56:37.464: I/ARRAY(868): 3
09-04 14:56:37.494: D/AbsListView(868): onVisibilityChanged() is called, visibility : 4
09-04 14:56:37.494: D/AbsListView(868): unregisterIRListener() is called 
09-04 14:56:37.494: D/AbsListView(868): onVisibilityChanged() is called, visibility : 0
09-04 14:56:37.494: D/AbsListView(868): unregisterIRListener() is called 
09-04 14:56:37.494: D/AbsListView(868): unregisterIRListener() is called 
09-04 14:56:37.504: D/AbsListView(868): onVisibilityChanged() is called, visibility : 0
09-04 14:56:37.504: D/AbsListView(868): unregisterIRListener() is called 
09-04 14:56:37.504: E/ViewRootImpl(868): sendUserActionEvent() mView == null
09-04 14:56:37.504: D/AbsListView(868): unregisterIRListener() is called 
09-04 14:56:37.524: I/Adreno-EGL(868): <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build:  (CL3869936)
09-04 14:56:37.524: I/Adreno-EGL(868): OpenGL ES Shader Compiler Version: 17.01.11.SPL
09-04 14:56:37.524: I/Adreno-EGL(868): Build Date: 01/17/14 Fri
09-04 14:56:37.524: I/Adreno-EGL(868): Local Branch: 
09-04 14:56:37.524: I/Adreno-EGL(868): Remote Branch: 
09-04 14:56:37.524: I/Adreno-EGL(868): Local Patches: 
09-04 14:56:37.524: I/Adreno-EGL(868): Reconstruct Branch: 
09-04 14:56:37.574: D/OpenGLRenderer(868): Enabling debug mode 0
09-04 14:56:37.715: D/dalvikvm(868): GC_FOR_ALLOC freed 204K, 34% free 17536K/26476K, paused 16ms, total 16ms
09-04 14:56:37.745: I/dalvikvm-heap(868): Grow heap (frag case) to 39.227MB for 18924856-byte allocation
09-04 14:56:37.745: W/SQLiteConnectionPool(868): A SQLiteConnection object for database '+data+data+com_example_kontaktysqllite+databases+kontakty_db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
09-04 14:56:37.785: D/AndroidRuntime(868): Shutting down VM
09-04 14:56:37.785: W/dalvikvm(868): threadid=1: thread exiting with uncaught exception (group=0x418e7da0)
09-04 14:56:37.805: E/AndroidRuntime(868): FATAL EXCEPTION: main
09-04 14:56:37.805: E/AndroidRuntime(868): Process: com.example.kontaktysqllite, PID: 868
09-04 14:56:37.805: E/AndroidRuntime(868): java.lang.NullPointerException
09-04 14:56:37.805: E/AndroidRuntime(868):  at com.example.sqllite.MainActivity$OrderAdapter.getView(MainActivity.java:109)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.AbsListView.obtainView(AbsListView.java:2715)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.ListView.makeAndAddView(ListView.java:1801)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.ListView.fillDown(ListView.java:697)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.ListView.fillFromTop(ListView.java:763)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.ListView.layoutChildren(ListView.java:1627)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.AbsListView.onLayout(AbsListView.java:2528)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.View.layout(View.java:15655)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.ViewGroup.layout(ViewGroup.java:4856)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.View.layout(View.java:15655)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.ViewGroup.layout(ViewGroup.java:4856)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.View.layout(View.java:15655)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.ViewGroup.layout(ViewGroup.java:4856)
09-04 14:56:37.805: E/AndroidRuntime(868):  at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:438)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.View.layout(View.java:15655)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.ViewGroup.layout(ViewGroup.java:4856)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.View.layout(View.java:15655)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.ViewGroup.layout(ViewGroup.java:4856)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2283)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2003)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1235)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6470)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.Choreographer.doCallbacks(Choreographer.java:603)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.Choreographer.doFrame(Choreographer.java:573)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.os.Handler.handleCallback(Handler.java:733)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.os.Handler.dispatchMessage(Handler.java:95)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.os.Looper.loop(Looper.java:157)
09-04 14:56:37.805: E/AndroidRuntime(868):  at android.app.ActivityThread.main(ActivityThread.java:5356)
09-04 14:56:37.805: E/AndroidRuntime(868):  at java.lang.reflect.Method.invokeNative(Native Method)
09-04 14:56:37.805: E/AndroidRuntime(868):  at java.lang.reflect.Method.invoke(Method.java:515)
09-04 14:56:37.805: E/AndroidRuntime(868):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
09-04 14:56:37.805: E/AndroidRuntime(868):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
09-04 14:56:37.805: E/AndroidRuntime(868):  at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

您将获得NullPointerException

ImageView img = (ImageView)findViewById(R.id.row_imageview);

请使用

ImageView img = (ImageView)v.findViewById(R.id.row_imageview);

imgv相同,在TextView name视图中。

希望这有帮助。