
运行以下应用程序时出现以下异常
活动:
package com.Google.androID.SmartStudentmCompanion;import java.io.BufferedReader;import java.io.IOException;import java.util.ArrayList;import java.util.List;import org.apache.http.httpResponse;import org.apache.http.nameValuePair;import org.apache.http.clIEnt.httpClIEnt;import org.apache.http.clIEnt.entity.UrlEncodedFormEntity;import org.apache.http.clIEnt.methods.httpPost;import org.apache.http.message.BasicnameValuePair;import org.apache.http.util.EntityUtils;import androID.app.Activity;import androID.content.Intent;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.Toast;public class Login extends Activity{ public static String ip_address="192.168.1.101"; EditText username; EditText password; button login; button exit; Toast toast; /** Called when the activity is first created. */ @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.loginscreen); System.out.println("onCreate()..."); username = (EditText) findVIEwByID(R.ID.username); password = (EditText) findVIEwByID(R.ID.password); this.login = (button)findVIEwByID(R.ID.loginbutton); this.login.setonClickListener(new VIEw.OnClickListener() { String usrnm; String pwd; @OverrIDe public voID onClick(VIEw v) { usrnm = username.getText().toString(); pwd = password.getText().toString(); System.out.println("onClick()..."); int length = 0; try { System.out.println("hello"); String page = executehttpPost(usrnm,pwd); System.out.println(page); length = page.length(); } catch (Exception e) { // Todo auto-generated catch block e.printstacktrace(); } if (length == 0){ Toast.makeText(getApplicationContext(), "InvalID username and/or password", Toast.LENGTH_SHORT).show(); } else { /*Toast.makeText(getApplicationContext(), "ValID username and password", Toast.LENGTH_SHORT).show();*/ Intent myIntent = new Intent(v.getContext(), VIDeoVIEwer.class); startActivityForResult(myIntent, 0); } } }); this.exit = (button)findVIEwByID(R.ID.exitbutton); this.exit.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { finish(); } }); } public String executehttpPost(String username, String password) throws Exception { BufferedReader in = null; try { ApplicationEx app = (ApplicationEx)this.getApplication(); httpClIEnt clIEnt = app.gethttpClIEnt(); httpPost request = new httpPost("http://"+ip_address+"/smartstudentmcompanion/check.PHP"); List<nameValuePair> postParameters = new ArrayList<nameValuePair>(); postParameters.add(new BasicnameValuePair("un", username)); postParameters.add(new BasicnameValuePair("pwd", password)); UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters); request.setEntity(formEntity); httpResponse response = clIEnt.execute(request); /*in = new BufferedReader(new inputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readline()) != null) { sb.append(line + NL); } in.close();*/ String page = EntityUtils.toString(response.getEntity()); System.out.println("page: " + page); return page; } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printstacktrace(); } } } }}应用:
package com.Google.androID.SmartStudentmCompanion;import org.apache.http.httpVersion;import org.apache.http.clIEnt.httpClIEnt;import org.apache.http.conn.ClIEntConnectionManager;import org.apache.http.conn.scheme.PlainSocketFactory;import org.apache.http.conn.scheme.Scheme;import org.apache.http.conn.scheme.SchemeRegistry;import org.apache.http.conn.ssl.SSLSocketFactory;import org.apache.http.impl.clIEnt.DefaulthttpClIEnt;import org.apache.http.impl.conn.tsccm.ThreadSafeClIEntConnManager;import org.apache.http.params.BasichttpParams;import org.apache.http.params.httpParams;import org.apache.http.params.httpProtocolParams;import org.apache.http.protocol.http;import androID.app.Application;import androID.util.Log;public class ApplicationEx extends Application { private static final String TAG = "ApplicationEx"; private httpClIEnt httpClIEnt; @OverrIDe public voID onCreate(){ super.onCreate(); httpClIEnt = createhttpClIEnt(); } @OverrIDe public voID onLowMemory() { super.onLowMemory(); shutdownhttpClIEnt(); } @OverrIDe public voID onTerminate() { super.onTerminate(); shutdownhttpClIEnt(); } private httpClIEnt createhttpClIEnt(){ Log.d(TAG,"createhttpClIEnt()..."); httpParams params = new BasichttpParams(); httpProtocolParams.setVersion(params, httpVersion.http_1_1); httpProtocolParams.setContentCharset(params, http.DEFAulT_CONTENT_CHARSET); httpProtocolParams.setUseExpectContinue(params, true); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClIEntConnectionManager conMgr = new ThreadSafeClIEntConnManager(params,schReg); return new DefaulthttpClIEnt(conMgr, params); } public httpClIEnt gethttpClIEnt() { return httpClIEnt; } private voID shutdownhttpClIEnt() { if(httpClIEnt!=null && httpClIEnt.getConnectionManager()!=null) { httpClIEnt.getConnectionManager().shutdown(); } }}表现:
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.Google.androID.SmartStudentmCompanion" androID:versionCode="1" androID:versionname="1.0"> <application androID:icon="@drawable/icon" androID:label="@string/app_name"> <activity androID:name=".Login" androID:label="@string/app_name"> <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity androID:name=".VIDeoVIEwer"></activity> </application> <uses-permission androID:name="androID.permission.INTERNET" /> <uses-sdk androID:minSdkVersion="8" /></manifest> 解决方法:
在你的明显改变
<application androID:icon="@drawable/icon" androID:label="@string/app_name">至
<application androID:icon="@drawable/icon" androID:label="@string/app_name" androID:name=".ApplicationEx">由于您尚未声明< applicaton>的androID:name, *** 作系统将查找默认的Application类.为了将其指向您的Application子类,您应该使用androID:name属性.
总结以上是内存溢出为你收集整理的android.app.Application上的android classcastexception全部内容,希望文章能够帮你解决android.app.Application上的android classcastexception所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)