【问题】
折腾:
期间,想要去创建HttpParams类型一个局部变量headerParams。
Eclipse帮我自动加的是:
HttpParams headerParams;
然后以为需要改为:
HttpParams headerParams = new HttpParams();
结果,就出错了:
如图:
即:
Cannot instantiate the type HttpParams |
【解决过程】
1.看着意思是,是type,所以无需new?
2.参考:
“Cannot instantiate the type…”
其对于其他类,是换别的,具体的某种类型,然后才能new。
3.参考:
Cannot instantiate the type HttpClient
然后再看到:
所以,去试试那个DefaultedHttpParams
HttpParams headerParams = new DefaultedHttpParams();
结果又提示:
The constructor DefaultedHttpParams() is undefined |
所以,再去按照Eclipse的提示,去修复为:
HttpParams headerParams = new DefaultedHttpParams(headerParams, headerParams);
也还是不知道如何继续。
4.然后去搞懂很多基本概念和参数的含义:
5.而改为这么写:
HttpParams headerParams = null; headerParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.TRUE);
结果又很明显不对,也有警告:
Null pointer access: The variable headerParams can only be null at this location |
6.后来随便去试了试,发现:
HttpParams headerParams = new BasicHttpParams();
是可以编译的通过的:
【总结】
暂时,就用BasicHttpParams吧,也不知道,后续会不会有什么限制。
转载请注明:在路上 » 【基本解决】java中没法new:Cannot instantiate the type HttpParams