rangoonshl 2014-04-11 05:47 采纳率: 0%
浏览 3559

运行时出现Unable to start activity ComponentIn错误,调试还会出现找不到源问题

做毕设遇到了问题,实在不知道怎么改了。。。求帮忙!!!
我做的是一个校园二手物品跳蚤市场,主要功能就是注册登录,查看各种类别的发布信息,用户自己发布信息,还有就是查看每条发布信息的详情。。
大部分代码都是我根据那个口袋微博的源码改的。。。
服务器用的是socket通信。
登录功能已经实现了,现在遇到的问题就是查看不了每条发布信息的详情!
主要错误是这样的:
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.wm.demo/org.wm.demo.GoodsDetailActivity}:java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:921)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) dalvik.system.NativeStart.main(Native Method)
Caused by:java.lang.NullPointerException
at org.wm.demo.GoodsDetailActivity.onCreate(GoodsDetailActivity.java:36)
at andriod.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at andriod.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
... 11 more

  • 写回答

3条回答

  • rangoonshl 2014-04-11 05:49
    关注

    下面是activity的代码:

    package org.wm.demo;

    import static org.wm.demo.ConstantUtil.SERVER_ADDRESS;
    import static org.wm.demo.ConstantUtil.SERVER_PORT;
    import java.util.*;
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.view.Gravity;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.BaseAdapter;
    import android.widget.LinearLayout;
    import android.widget.ListView;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.widget.AdapterView.OnItemClickListener;

    public class GoodsDetailActivity extends Activity {
    MyConnector mc = null;
    String[] sa = null;
    String uno = null;
    int rid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.goodsdetail);
    Intent intent = getIntent();
    uno = intent.getStringExtra("2"); // 2数字获取用户ID,前面程序有点问题,然后随便用某个字符替代了
    rid = intent.getIntExtra("3", -1); // 同上注释
    getInformationList();
    TextView price = (TextView) findViewById(R.id.price);
    price.setText(String.format("%s", sa[1]));
    TextView description = (TextView) findViewById(R.id.description);
    description.setText(String.format("%s", sa[2]));
    TextView contacts = (TextView) findViewById(R.id.contacts);
    contacts.setText(String.format("%s", sa[3]));
    TextView phone = (TextView) findViewById(R.id.phone);
    phone.setText(String.format("%s", sa[4]));
    TextView address = (TextView) findViewById(R.id.address);
    address.setText(String.format("%s", sa[5]));

    if (sa.length == 0) {
    Toast.makeText(GoodsDetailActivity.this, "这里空空如也!",
    Toast.LENGTH_LONG).show();
    }
    }

    // 方法:获取信息列表
    public void getInformationList() {
    new Thread() {
    public void run() {
    try {
    mc = new MyConnector(SERVER_ADDRESS, SERVER_PORT);
    mc.dout.writeUTF("<#GET_DETAILINFORMATION#>" + rid + "|"

    • "1"); int size = mc.din.readInt(); // 读取信息的长度 for (int i = 0; i < size; i++) { // 循环接受信息 String goodsInfo = mc.din.readUTF(); // 读取信息 sa = goodsInfo.split("\|"); } } catch (Exception e) { e.printStackTrace(); } } }.start(); }

    @Override
    protected void onDestroy() {
    if (mc != null) {
    mc.sayBye();
    mc = null;
    }
    super.onDestroy();
    }

    }

    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度