Caused by: java.lang.NullPointerException at org.springframework.beans.factory.support.DefaultLis

版权声明:整理不易,转载请注明出处。 https://blog.csdn.net/linmengmeng_1314/article/details/79966321

在搭建完Spring环境之后运行第一个demo的时候 就碰到这个问题,折腾了一天了,到现在才解决,记录一下自己的失误。
解决办法就是在添加user Library的时候 不能勾选System Library,否则后面运行demo的时候会提示空指针异常,这个真的是很郁闷。
这里写图片描述

下面内容为转载的,就是看了别人的博客才发现自己的失误的,学习大神的分析思路:

Caused by: java.lang.NullPointerException
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.<clinit>(DefaultListableBeanFactory.java:106)
   ... 7 more

一看源代码,是这样的:

static{  
    ClassLoader cl =DefaultListableBeanFactory.class.getClassLoader();  
    try{  
        javaxInjectProviderClass = cl.loadClass("javax.inject.Provider");//Line 106  
    }  
    catch(ClassNotFoundException ex){  
        // JSR-330 API not available - Provider interface simply not supported then.  
    }  
}  

源代码的问题在于:

ClassLoader cl =DefaultListableBeanFactory.class.getClassLoader();返回空!

找了找网上:发现别人也遇到过:

http://stackoverflow.com/questions/2272354/why-do-i-get-a-nullpointerexception-when-initializing-spring

再了解了一下getClassLoader() 的原理:

http://blog.chenlb.com/2009/06/java-classloader-architecture.html

原来是这个DefaultListableBeanFactory通过BootStrap直接加载,getClassLoader()的时候返回null

JDK上也有说明:

“public ClassLoader ‍getClassLoader()返回该类的类加载器。有些实现可能使用 null 来表示引导类加载器。如果该类由引导类加载器加载,则此方法在这类实现中将返回 null。 “

细细想来,原来是这里错了:勾选了System library(added to the boot class path),DefaultListableBeanFactory被当成系统Jar通过BootStrap直接加载

阅读更多

Caused by: java.lang.NullPointerException 问题求助!

09-01

错误日志:rnrn[img=http://img.bbs.csdn.net/upload/201409/01/1409554054_784837.jpg][/img]rn[img=http://img.bbs.csdn.net/upload/201409/01/1409554067_766584.jpg][/img]rnrn代码:rnrn[code=java] rnpublic class ChatActivity extends BaseActivity implements OnClickListener rn rn public static final String COPY_IMAGE = "EASEMOBIMG";rn public static final int REQUEST_CODE_COPY_AND_PASTE = 11;rn rn private ImageView micImage;rn private Drawable[] micImages;rn private View more;rn private LinearLayout expressionContainer;rn private LinearLayout btnContainer;rn rn // 给谁发送消息rnrn rn private ImageView iv_emoticons_normal;rn private ImageView iv_emoticons_checked;rn private RelativeLayout edittext_layout;rn private Button btnMore;rn private ListView listView;rn private InputMethodManager manager;rn rn rnrn @Overridern protected void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity_main);rn initView();rn rn rn /**rn * initViewrn */rn protected void initView() rn micImage = (ImageView) findViewById(R.id.mic_image);rn more = findViewById(R.id.more);rn listView = (ListView) findViewById(R.id.list);rn btnContainer = (LinearLayout) findViewById(R.id.ll_btn_container);rn expressionContainer = (LinearLayout) findViewById(R.id.ll_face_container);rn rn rn @Overridern public void onClick(View v) rn edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);rn more.setVisibility(View.GONE);rn iv_emoticons_normal.setVisibility(View.VISIBLE);rn iv_emoticons_checked.setVisibility(View.INVISIBLE);rn expressionContainer.setVisibility(View.GONE);rn btnContainer.setVisibility(View.GONE);rn rn rn rn private void setUpView() rn rn manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);rn listView.setOnTouchListener(new OnTouchListener() rnrn @Overridern public boolean onTouch(View v, MotionEvent event) rn hideKeyboard();rn more.setVisibility(View.GONE);rn iv_emoticons_normal.setVisibility(View.VISIBLE);rn iv_emoticons_checked.setVisibility(View.INVISIBLE);rn expressionContainer.setVisibility(View.GONE);rn btnContainer.setVisibility(View.GONE);rn return false;rn rn rn );rn rn rn /**rn * 显示或隐藏图标按钮页rn * rn * @param viewrn */rn public void more(View view) rn if (more.getVisibility() == View.GONE) rn System.out.println("more gone");rn hideKeyboard();rn more.setVisibility(View.VISIBLE);rn btnContainer.setVisibility(View.VISIBLE);rn expressionContainer.setVisibility(View.GONE);rn else rn if (expressionContainer.getVisibility() == View.VISIBLE) rn expressionContainer.setVisibility(View.GONE);rn btnContainer.setVisibility(View.VISIBLE);rn iv_emoticons_normal.setVisibility(View.VISIBLE);rn iv_emoticons_checked.setVisibility(View.INVISIBLE);rn else rn more.setVisibility(View.GONE);rn rnrn rnrn rnrn /**rn * 点击文字输入框rn * rn * @param vrn */rn public void editClick(View v) rn listView.setSelection(listView.getCount() - 1);rn if (more.getVisibility() == View.VISIBLE) rn more.setVisibility(View.GONE);rn iv_emoticons_normal.setVisibility(View.VISIBLE);rn iv_emoticons_checked.setVisibility(View.INVISIBLE);rn rnrn rn rn rn public List getExpressionRes(int getSum) rn List reslist = new ArrayList();rn for (int x = 1; x <= getSum; x++) rn String filename = "ee_" + x;rnrn reslist.add(filename);rnrn rn return reslist;rnrn rn rn /**rn * 隐藏软键盘rn */rn private void hideKeyboard() rn if (getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) rn if (getCurrentFocus() != null)rn manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);rn rn rn rn [/code]rnrn求解错误在哪里?

android开发Caused by: java.lang.NullPointerException

08-20

08-20 17:19:32.790: D/dalvikvm(938): GC_EXTERNAL_ALLOC freed 52K, 51% free 2686K/5379K, external 0K/0K, paused 397msrn08-20 17:19:33.200: D/AndroidRuntime(938): Shutting down VMrn08-20 17:19:33.200: W/dalvikvm(938): threadid=1: thread exiting with uncaught exception (group=0x40020560)rn08-20 17:19:33.210: E/AndroidRuntime(938): FATAL EXCEPTION: mainrn08-20 17:19:33.210: E/AndroidRuntime(938): java.lang.RuntimeException: Unable to start activity ComponentInfocom.example.suishoukan/com.example.suishoukan.MainActivity: java.lang.NullPointerExceptionrn08-20 17:19:33.210: E/AndroidRuntime(938): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1834)rn08-20 17:19:33.210: E/AndroidRuntime(938): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1850)rn08-20 17:19:33.210: E/AndroidRuntime(938): at android.app.ActivityThread.access$1500(ActivityThread.java:125)rn08-20 17:19:33.210: E/AndroidRuntime(938): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:941)rn08-20 17:19:33.210: E/AndroidRuntime(938): at android.os.Handler.dispatchMessage(Handler.java:99)rn08-20 17:19:33.210: E/AndroidRuntime(938): at android.os.Looper.loop(Looper.java:130)rn08-20 17:19:33.210: E/AndroidRuntime(938): at android.app.ActivityThread.main(ActivityThread.java:3962)rn08-20 17:19:33.210: E/AndroidRuntime(938): at java.lang.reflect.Method.invokeNative(Native Method)rn08-20 17:19:33.210: E/AndroidRuntime(938): at java.lang.reflect.Method.invoke(Method.java:507)rn08-20 17:19:33.210: E/AndroidRuntime(938): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)rn08-20 17:19:33.210: E/AndroidRuntime(938): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)rn08-20 17:19:33.210: E/AndroidRuntime(938): at dalvik.system.NativeStart.main(Native Method)rn08-20 17:19:33.210: E/AndroidRuntime(938): Caused by: java.lang.NullPointerExceptionrn08-20 17:19:33.210: E/AndroidRuntime(938): at com.example.suishoukan.MainActivity.show(MainActivity.java:85)rn08-20 17:19:33.210: E/AndroidRuntime(938): at com.example.suishoukan.MainActivity.onCreate(MainActivity.java:54)rn08-20 17:19:33.210: E/AndroidRuntime(938): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)rn08-20 17:19:33.210: E/AndroidRuntime(938): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1788)rn08-20 17:19:33.210: E/AndroidRuntime(938): ... 11 morern[code=Java]rnpackage com.example.suishoukan;rnrnimport java.util.ArrayList;rnimport java.util.HashMap;rnimport java.util.List;rnrnimport com.example.domain.Film;rnimport com.example.service.FilmService;rnimport com.example.test.FilmServiceTest;rnrnimport android.app.TabActivity;rnimport android.os.Bundle;rnimport android.util.Log;rnimport android.view.View;rnimport android.view.View.OnClickListener;rnimport android.widget.Button;rnimport android.widget.ListView;rnimport android.widget.SimpleAdapter;rnimport android.widget.TabHost;rnimport android.widget.TabHost.OnTabChangeListener;rnrnpublic class MainActivity extends TabActivityrnrn //声明TabHost对象rn TabHost mTabHost;rn Button button1,button2,button3,button4;rn FilmService filmService;rn List films;rn ListView listView;rn public void onCreate(Bundle savedInstanceState)rn rn super.onCreate(savedInstanceState);rn setContentView(R.layout.main);rn //取得TabHost对象rn mTabHost = getTabHost();rn rn /* 为TabHost添加标签 */rn //新建一个newTabSpec(newTabSpec)rn //设置其标签和图标(setIndicator)rn //设置内容(setContent)rn mTabHost.addTab(mTabHost.newTabSpec("tab_test1")rn .setIndicator("榜单")rn .setContent(R.id.textview1));rn mTabHost.addTab(mTabHost.newTabSpec("tab_test2")rn .setIndicator("节目表")rn .setContent(R.id.textview2));rn mTabHost.addTab(mTabHost.newTabSpec("tab_test3")rn .setIndicator("收藏")rn .setContent(R.id.textview3));rn //设置当前显示哪一个标签rn mTabHost.setCurrentTab(0);rn filmService = new FilmService(this);rn films = filmService.getScrollData(0,10);rn listView = (ListView) this.findViewById(R.id.listView) ;rn button1 = (Button) this.findViewById(R.id.button1);rn button2 = (Button) this.findViewById(R.id.button2);rn button3 = (Button) this.findViewById(R.id.button3);rn button4 = (Button) this.findViewById(R.id.button4);rn OnClickListener o = new OnClickListener() rn @Overridern public void onClick(View v) rn // TODO Auto-generated method stubrn if(button1.getId()==v.getId())rn films = filmService.getScrollData(0,10);rn rn else if(button2.getId()==v.getId())rn films = filmService.getScrollData(10,10);rn rn else if(button3.getId()==v.getId())rn films = filmService.getScrollData(20,10);rn rn elsern films = filmService.getScrollData(30,10);rn rn rn ;rn button1.setOnClickListener(o);rn button2.setOnClickListener(o);rn button3.setOnClickListener(o);rn button4.setOnClickListener(o);rn show();rn rn private void show() rn // TODO Auto-generated method stubrn List> data = new ArrayList>();rn for(Film film : films)rn HashMap item = new HashMap();rn item.put("title", film.getTitle());rn item.put("score", film.getScore());rn data.add(item);rn rn SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.item,rn new String[]"title","score", new int[]R.id.title,R.id.score);rn listView.setAdapter(adapter);rn rnrnrn[/code]

Caused by: java.lang.NullPointerException 这是怎么回事?

06-24

[img=http://img.bbs.csdn.net/upload/201606/24/1466729391_552047.png][/img][code=java][/code] package com.example.school;rnrnimport java.util.ArrayList;rnimport java.util.HashMap;rnimport java.util.List;rnimport java.util.Map;rnimport java.util.Random;rnrnimport com.example.school.R;rnrnimport android.os.Bundle;rnimport android.app.Activity;rnimport android.content.Intent;rnimport android.view.Menu;rnimport android.view.View;rnimport android.view.View.OnClickListener;rnimport android.widget.AdapterView;rnimport android.widget.AdapterView.OnItemSelectedListener;rnimport android.widget.Button;rnimport android.widget.GridView;rnimport android.widget.SimpleAdapter;rnimport android.widget.Spinner;rnimport android.widget.Toast;rnimport android.app.Activity;rnimport android.os.Bundle;rnimport android.os.Handler;rnimport android.os.Message;rnimport android.widget.ImageView;rnimport android.widget.TextView;rnrnrnrnrnpublic class MainActivity extends Activity implements Runnable rnrn private ImageView iv;rn private Handler handler;rn private int[] path = new int[] R.drawable.img08, R.drawable.img09,rn R.drawable.img10, R.drawable.img11, R.drawable.img12,rn R.drawable.img13 ; // 保存广告图片的数组rn rn @Overridern protected void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity_main);rn rn iv=(ImageView)findViewById(R.id.imageView2);rn Thread t=new Thread(this);rn t.start();rn handler=new Handler()rn @Overridern public void handleMessage(Message msg)rn TextView tv=(TextView)findViewById(R.id.textView1);rn if(msg.what==0x101)rn //tv.setText(msg.getData().getString("title"));rn iv.setImageResource(path[msg.arg1]);rn rn super.handleMessage(msg);rn rn ;rn rn rnrn Button showtext = (Button)findViewById(R.id.button1);rn Button showimage=(Button)findViewById(R.id.button2);rn final Intent intent = new Intent(MainActivity.this,showtext.class);rn final Intent image = new Intent(MainActivity.this,showimage.class);rn final int CODE=0x111;rn final int CODE2=0x112;rn showtext.setOnClickListener(new OnClickListener()rnrn @Overridern public void onClick(View v) rn startActivityForResult(intent,CODE);rn rn rn );rn showimage.setOnClickListener(new OnClickListener()rnrn @Overridern public void onClick(View v) rn startActivityForResult(image,CODE2);rn rn rn );rn rn rn rn rn rn rnrn @Overridern public void run() rn // TODO Auto-generated method stubrn int index=0;rn while(!Thread.currentThread().isInterrupted())rn index=new Random().nextInt(path.length);rn Message m =handler.obtainMessage();rn m.arg1=index;rn Bundle bundle=new Bundle();rn m.what=0x101;rn //bundle.putString("title", title[index]);rn m.setData(bundle);rn handler.sendMessage(m);rn tryrn Thread.sleep(2000);rn catch(InterruptedException e)rn e.printStackTrace();rn rn rn rnrnrnrn

android开发中Caused by: java.lang.NullPointerException

10-10

main.xml文rn[code=css]rn rn rn rnrnrn[/code]rnrnrnmainActivity.javarn[code=java]package com.example.ratingbarproject1;rnrnimport android.os.Bundle;rnimport android.app.Activity;rnimport android.view.Menu;rnimport android.widget.RatingBar;rnimport android.widget.RatingBar.OnRatingBarChangeListener;rnimport android.widget.TextView;rnrnpublic class MainActivity extends Activity rn private RatingBar ratingbar=null;rn private TextView textview=null;rn protected void onCreate(Bundle savedInstanceState) rn this.ratingbar=(RatingBar)super.findViewById(R.id.mybar1);//获取组件rn this.textview=(TextView)super.findViewById(R.id.mytext);rn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity_main);rn this.ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener1());//设置监听rn rnprivate class OnRatingBarChangeListener1 implements OnRatingBarChangeListenerrn //@Overridern public void onRatingChanged(RatingBar ratingBar, float rating,rn boolean fromUser) rn // 在显示文本中显示星星rn MainActivity.this.textview.append("***当前的星评分:"rn +ratingBar.getNumStars()+"***当前的步长:"+ratingBar.getStepSize()+"\n");rn rn rnrn @Overridern public boolean onCreateOptionsMenu(Menu menu) rn // Inflate the menu; this adds items to the action bar if it is present.rn getMenuInflater().inflate(R.menu.main, menu);rn return true;rn rnrnrn[/code]rnrnrnrn错误。。。。。。。。。。。。。。。。rn

没有更多推荐了,返回首页