2 fengwanlu95 fengwanlu95 于 2014.05.13 16:08 提问

android程序,eclipse没报错,但是运行会意外停止

我是一个初学android者,很多简单的问题大家都看着很简单而我不知道为什么,所以希望耐心的大神帮忙回答一下!我很着急~~~
这是OtherActivity.java

public class OtherActivity extends MainActivity {

private Button btn1;
private TextView myTextView = null;
private ListView listView;
private SimpleAdapter adapter;
private DBUtil dbUtil;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.other);
    Intent intent = getIntent();
    String value = intent.getStringExtra("testIntent");
    myTextView = (TextView)findViewById(R.id.myTextView);
    myTextView.setText(value);

    btn1 = (Button) findViewById(R.id.btn_all);
    listView = (ListView) findViewById(R.id.listView);
    dbUtil = new DBUtil();
    btn1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            hideButton(true);
            setListView();

        }
    });

}
 private void setListView() {

    listView.setVisibility(View.VISIBLE);

    List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

    String str = "select * from v_jy where enginen like '%" + "enginen" + "%'";
    list = dbUtil.selectAllfromv_jy(str);
    adapter = new SimpleAdapter(
    OtherActivity.this, 
    list, 
    R.layout.adapter_item, 
    new String[] {"sysid", "reportn", "enginen" ,"exreport","exsdate","uaddress","maddress","factoryn","exaddress","no" }, 
    new int[] { R.id.txt_Cno,R.id.txt_Cna,R.id.txt_Cnb,R.id.txt_Cnc,R.id.txt_Cnd,R.id.txt_Cne,R.id.txt_Cnf,R.id.txt_Cng,R.id.txt_Cnh,R.id.txt_Cni});

    listView.setAdapter(adapter);

}

DBUtil.java如下:
public class DBUtil {
//private static final String Soaptest = null;
private ArrayList arrayList = new ArrayList();
private ArrayList brrayList = new ArrayList();
private ArrayList crrayList = new ArrayList();
private HttpConnSoap Soap = new HttpConnSoap();

public static Connection getConnection() {
    Connection con = null;
    try {
        //Class.forName("org.gjt.mm.mysql.Driver");
        //con=DriverManager.getConnection("jdbc:mysql://192.168.0.106:3306/test?useUnicode=true&characterEncoding=UTF-8","root","initial");             
    } catch (Exception e) {
        //e.printStackTrace();
    }
    return con;
}


    public List<HashMap<String, String>> selectAllfromv_jy(String enginen) {
    List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

    arrayList.clear();
    brrayList.clear();
    crrayList.clear();

    arrayList.add("enginen");
    brrayList.add(enginen);
    crrayList = Soap.GetWebServer("selectAllfromv_jy", arrayList, brrayList);

    Soap.GetWebServer("selectAllfromv_jy", arrayList, brrayList);
    HashMap<String, String> tempHash = new HashMap<String, String>();

    tempHash.put("sysid", "sysid");
    tempHash.put("reportn", "reportn");
    tempHash.put("enginen", "enginen");
    tempHash.put("exreport", "exreport");
    tempHash.put("exsdate", "exsdate");
    tempHash.put("uaddress", "uaddress");
    tempHash.put("maddress", "maddress");
    tempHash.put("factoryn", "factoryn");
    tempHash.put("exaddress", "exaddress");
    tempHash.put("no", "no");
    list.add(tempHash);
    //DBUtil dbUtil = null;
    //list = dbUtil.getAllfromv_jy();

    for (int j = 0; j < crrayList.size(); j += 10) {
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("sysid", crrayList.get(j));
        hashMap.put("reportn", crrayList.get(j + 1));
        hashMap.put("enginen", crrayList.get(j + 2));
        hashMap.put("exreport", crrayList.get(j + 3));
        hashMap.put("exsdate ", crrayList.get(j + 4));
        hashMap.put("uaddress", crrayList.get(j + 5));
        hashMap.put("maddress", crrayList.get(j + 6));
        hashMap.put("factoryn", crrayList.get(j + 7));
        hashMap.put("exaddress", crrayList.get(j + 8));
        hashMap.put("no", crrayList.get(j + 9));
        list.add(hashMap);
    }
    return list;

}

logcat代码:
05-13 16:07:18.040: I/System.out(14028): /soap:Body
05-13 16:07:18.040: D/AndroidRuntime(14028): Shutting down VM
05-13 16:07:18.040: W/dalvikvm(14028): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
05-13 16:07:18.050: E/AndroidRuntime(14028): FATAL EXCEPTION: main
05-13 16:07:18.050: E/AndroidRuntime(14028): java.lang.NullPointerException
05-13 16:07:18.050: E/AndroidRuntime(14028): at com.example.crane5.DBUtil.selectAllfromv_jy(DBUtil.java:66)
05-13 16:07:18.050: E/AndroidRuntime(14028): at com.example.crane5.OtherActivity.setListView(OtherActivity.java:61)
05-13 16:07:18.050: E/AndroidRuntime(14028): at com.example.crane5.OtherActivity.access$1(OtherActivity.java:54)
05-13 16:07:18.050: E/AndroidRuntime(14028): at com.example.crane5.OtherActivity$1.onClick(OtherActivity.java:48)
05-13 16:07:18.050: E/AndroidRuntime(14028): at android.view.View.performClick(View.java:2538)
05-13 16:07:18.050: E/AndroidRuntime(14028): at android.view.View$PerformClick.run(View.java:9152)
05-13 16:07:18.050: E/AndroidRuntime(14028): at android.os.Handler.handleCallback(Handler.java:587)
05-13 16:07:18.050: E/AndroidRuntime(14028): at android.os.Handler.dispatchMessage(Handler.java:92)
05-13 16:07:18.050: E/AndroidRuntime(14028): at android.os.Looper.loop(Looper.java:130)
05-13 16:07:18.050: E/AndroidRuntime(14028): at android.app.ActivityThread.main(ActivityThread.java:3691)
05-13 16:07:18.050: E/AndroidRuntime(14028): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 16:07:18.050: E/AndroidRuntime(14028): at java.lang.reflect.Method.invoke(Method.java:507)
05-13 16:07:18.050: E/AndroidRuntime(14028): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
05-13 16:07:18.050: E/AndroidRuntime(14028): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
05-13 16:07:18.050: E/AndroidRuntime(14028): at dalvik.system.NativeStart.main(Native Method)

2个回答

hhp5127447
hhp5127447   2014.05.14 09:57

05-13 16:07:18.050: E/AndroidRuntime(14028): java.lang.NullPointerException
这是提示空指针错误!
DBUtil.java:66、OtherActivity.java:61、OtherActivity.java:54、OtherActivity.java:48这些都是运行不过去的地方,后面的数字是表示错误出现在该页面的哪一行。具体情况没看清楚,你可以按照这些错误点去修改下!有可能是一开始的源头:空指针错误引起后面的无法继续解释,也就是说可能就是只有一个问题,解决了就可以运行了

ns2leach
ns2leach   2016.05.09 22:48

你的问题是怎么解决的啊,我也遇到了这个问题

Csdn user default icon
上传中...
上传图片
插入图片