android_com
2015-07-24 01:05
采纳率: 33.3%
浏览 1.8k

Android中空指针异常的具体错误改正

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

private ImageView zy, ZyImge;
private TextView ZyLine, ZyLeade, ZyAb;
private String url;


private SimpleAdapter adapter;
private DBUtil dbUtil;
protected static final int MSG_OK = 0;
private ListView lv = null;
//private MyAdapter myAdapter = null;
private List<Card> list = new ArrayList<Card>();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.adapter_item);
    zy = (ImageView) findViewById(R.id.zhengyou_list_img);
    ZyImge = (ImageView) findViewById(R.id.zhengyou_list_luxian);
    ZyLeade = (TextView) findViewById(R.id.zhengyou_list_name);
    ZyLine = (TextView) findViewById(R.id.zhengyou_list_title);
    ZyAb = (TextView) findViewById(R.id.zhengyou_list_time);

    final String ZyLines = getIntent().getExtras().getString("ZyLines");
    final String ZyImage = getIntent().getExtras().getString("ZyImage");
    final String ZyLeader = getIntent().getExtras().getString("ZyLeader");
    final String ZyAbs = getIntent().getExtras().getString("ZyAbs");

    ZyLine.setText(ZyLines);

    ZyLeade.setText(ZyLeader);
    ZyAb.setText(ZyAbs);


}

}

logcat中错误提示:
Caused by: java.lang.NullPointerException
07-24 09:00:34.209: E/AndroidRuntime(9339): at com.example.lianwang.MainActivity.onCreate(MainActivity.java:55)
07-24 09:00:34.209: E/AndroidRuntime(9339): at android.app.Activity.performCreate(Activity.java:5122)
07-24 09:00:34.209: E/AndroidRuntime(9339): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
07-24 09:00:34.209: E/AndroidRuntime(9339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)

我想问如何改正,错误的原因是什么

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • danielinbiti 2015-07-24 01:11
    MainActivity.java:55
     看一下MainActivity.java第55行是什么
     这里可能空指针的一般看findViewById有没有找到对应的组件,如果没找到
     ZyLine.setText(ZyLines); 
        ZyLeade.setText(ZyLeader);
        ZyAb.setText(ZyAbs);
            上面几个都会报空指针
            另外看参数都否传入getIntent().getExtras()
    
            这段代码主要这两种空指针
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题