请问为什么运行的时候log cat报错?
import java.io.IOException; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import com.weibo.sdk.android.Oauth2AccessToken; import com.weibo.sdk.android.Weibo; import com.weibo.sdk.android.WeiboAuthListener; import com.weibo.sdk.android.WeiboDialogError; import com.weibo.sdk.android.WeiboException; import com.weibo.sdk.android.api.StatusesAPI; import com.weibo.sdk.android.net.RequestListener; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; public class WeatherActivity extends Activity { private static final String CONSUMER_KEY = "1646212860";// 替换为开发者的appkey,例如"1646212860"; private static final String REDIRECT_URL = "http://www.sina.com"; static Oauth2AccessToken accessToken; Weibo mWeibo; EditText et = (EditText) findViewById(R.id.editText1); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE);// ȥ�����8 setContentView(R.layout.main); Button b = (Button) findViewById(R.id.button1); Button b2 = (Button) findViewById(R.id.button2); Button b3 = (Button) findViewById(R.id.button3); mWeibo = Weibo.getInstance(CONSUMER_KEY, REDIRECT_URL); b.setOnClickListener(new OnClickListener(){ public void onClick(View v){ String cityname = et.getText().toString(); getWeather(cityname); } }); b2.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub mWeibo.authorize(WeatherActivity.this, new AuthDialogListener()); }}); b3.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub String cityname = et.getText().toString(); share(cityname); } }); } protected void getWeather(String city){ String WSDL_URI = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx";//wsdl ��uri String namespace = "http://WebXml.com.cn/";//namespace String methodName = "getWeather";//Ҫ���õķ������ SoapObject request = new SoapObject(namespace, methodName); request.addProperty("theCityCode", city); try{ //����SoapSerializationEnvelope ����ͬʱָ��soap�汾��(֮ǰ��wsdl�п�����) SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER12); envelope.bodyOut = request;//�����Ƿ�����������������bodyOut envelope.dotNet = true;//������.net������webservice����������Ҫ����Ϊtrue HttpTransportSE httpTransportSE = new HttpTransportSE(WSDL_URI); httpTransportSE.call(null, envelope);//���� SoapObject response = (SoapObject) envelope.getResponse();//��÷��ض��� if(response!=null){ TextView t1 = (TextView) findViewById(R.id.textView1); t1.setText(response.getProperty(1).toString()); TextView t2 = (TextView) findViewById(R.id.textView2); t2.setText(response.getProperty(3).toString()); TextView t3 = (TextView) findViewById(R.id.textView3); t3.setText(response.getProperty(4).toString()); TextView t4 = (TextView) findViewById(R.id.textView4); t4.setText(response.getProperty(5).toString()); ImageView im1 = (ImageView) findViewById(R.id.imageView1); int icon1 =parseIcon(response.getProperty(10).toString()); im1.setImageResource(icon1); ImageView im2 = (ImageView) findViewById(R.id.imageView2); int icon2 =parseIcon(response.getProperty(11).toString()); im2.setImageResource(icon2); } }catch(Exception e){ e.printStackTrace(); } } protected void share(String city){ String WSDL_URI = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx";//wsdl ��uri String namespace = "http://WebXml.com.cn/";//namespace String methodName = "getWeather";//Ҫ���õķ������ SoapObject request = new SoapObject(namespace, methodName); request.addProperty("theCityCode", city); try{ //����SoapSerializationEnvelope ����ͬʱָ��soap�汾��(֮ǰ��wsdl�п�����) SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER12); envelope.bodyOut = request;//�����Ƿ�����������������bodyOut envelope.dotNet = true;//������.net������webservice����������Ҫ����Ϊtrue HttpTransportSE httpTransportSE = new HttpTransportSE(WSDL_URI); httpTransportSE.call(null, envelope);//���� SoapObject response = (SoapObject) envelope.getResponse();//��÷��ض��� if(response!=null){ StatusesAPI sa = new StatusesAPI(accessToken); String content = response.getProperty(1).toString() + " " + response.getProperty(3).toString() + " " + response.getProperty(4).toString(); sa.update(content, "0", "0", listener); } }catch(Exception e){ e.printStackTrace(); } } // ���߷������÷�������ѷ��ص�����ͼ���ַ�ת��Ϊ�����ͼƬ��ԴID�� private int parseIcon(String strIcon) { if (strIcon == null) return -1; if ("0.gif".equals(strIcon)) return R.drawable.a_0; if ("1.gif".equals(strIcon)) return R.drawable.a_1; if ("2.gif".equals(strIcon)) return R.drawable.a_2; if ("3.gif".equals(strIcon)) return R.drawable.a_3; if ("4.gif".equals(strIcon)) return R.drawable.a_4; if ("5.gif".equals(strIcon)) return R.drawable.a_5; if ("6.gif".equals(strIcon)) return R.drawable.a_6; if ("7.gif".equals(strIcon)) return R.drawable.a_7; if ("8.gif".equals(strIcon)) return R.drawable.a_8; if ("9.gif".equals(strIcon)) return R.drawable.a_9; if ("10.gif".equals(strIcon)) return R.drawable.a_10; if ("11.gif".equals(strIcon)) return R.drawable.a_11; if ("12.gif".equals(strIcon)) return R.drawable.a_12; if ("13.gif".equals(strIcon)) return R.drawable.a_13; if ("14.gif".equals(strIcon)) return R.drawable.a_14; if ("15.gif".equals(strIcon)) return R.drawable.a_15; if ("16.gif".equals(strIcon)) return R.drawable.a_16; if ("17.gif".equals(strIcon)) return R.drawable.a_17; if ("18.gif".equals(strIcon)) return R.drawable.a_18; if ("19.gif".equals(strIcon)) return R.drawable.a_19; if ("20.gif".equals(strIcon)) return R.drawable.a_20; if ("21.gif".equals(strIcon)) return R.drawable.a_21; if ("22.gif".equals(strIcon)) return R.drawable.a_22; if ("23.gif".equals(strIcon)) return R.drawable.a_23; if ("24.gif".equals(strIcon)) return R.drawable.a_24; if ("25.gif".equals(strIcon)) return R.drawable.a_25; if ("26.gif".equals(strIcon)) return R.drawable.a_26; if ("27.gif".equals(strIcon)) return R.drawable.a_27; if ("28.gif".equals(strIcon)) return R.drawable.a_28; if ("29.gif".equals(strIcon)) return R.drawable.a_29; if ("30.gif".equals(strIcon)) return R.drawable.a_30; if ("31.gif".equals(strIcon)) return R.drawable.a_31; return 0; } class AuthDialogListener implements WeiboAuthListener{ @Override public void onCancel() { // TODO Auto-generated method stub } @Override public void onComplete(Bundle arg0) { // TODO Auto-generated method stub String token = arg0.getString("access_token"); String expires_in = arg0.getString("expires_in"); WeatherActivity.accessToken = new Oauth2AccessToken(token, expires_in); } @Override public void onError(WeiboDialogError arg0) { // TODO Auto-generated method stub } @Override public void onWeiboException(WeiboException arg0) { // TODO Auto-generated method stub }} RequestListener listener = new RequestListener(){ @Override public void onComplete(String arg0) { // TODO Auto-generated method stub } @Override public void onError(WeiboException arg0) { // TODO Auto-generated method stub } @Override public void onIOException(IOException arg0) { // TODO Auto-generated method stub }}; }
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.weather2/com.example.weather2.WeatherActivity}: java.lang.NullPointerException
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
你把EditTextet=(EditText)findViewById(R.id.editText1);
放在setContentView(R.layout.main);后面试试吧。
看下面的代码:
publicViewfindViewById(intid){
returngetWindow().findViewById(id);}
publicWindowgetWindow(){
returnmWindow;
}
不知道什么原因,
不过EditTextet=(EditText)findViewById(R.id.editText1);
这句放在onCreate外什么意思
去年毕设我同学就是用这个程序的....o(︶︿︶)o唉
请问是什么问题吗?从图中weather2.weatherActivity空指针回复 @-Mop-:运行时异常哈!报错是不能实例化!请问应该怎么改正(┳_┳)...单步调试一下看看。自己调试一下就知道了,拿出这么长的代码问。。。