做毕设遇到了问题,实在不知道怎么改了。。。求帮忙!!!
我做的是一个校园二手物品跳蚤市场,主要功能就是注册登录,查看各种类别的发布信息,用户自己发布信息,还有就是查看每条发布信息的详情。。
大部分代码都是我根据那个口袋微博的源码改的。。。
服务器用的是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
下面是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 + "|"
@Override
protected void onDestroy() {
if (mc != null) {
mc.sayBye();
mc = null;
}
super.onDestroy();
}
}
at org.wm.demo.GoodsDetailActivity.onCreate(GoodsDetailActivity.java:36)
提示你36行存在空指针的问题。
36行空指针异常,做一下空指针异常判定。