android 应用程序在调试时出现强制关闭的信息,造成这种情况的可能性有哪些以及具体的解决方法
主程序 Demo:package softdevonline.Demo;
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Demo extends Activity {
//String Text;
String LoginVertifyResult;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if(checkNetworkInfo())
{
Button ConfrimButton=(Button)findViewById(R.id.Button1);
ConfrimButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
//LoadProgressDialog();
showContent();
}
});
}
}
private boolean checkNetworkInfo()
{
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);//获取网络通讯类的实例
//mobile 3G Data Network
State mobile= conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();//TYPE_MOBILE=0
//txt3G.setText(mobile.toString());
//wifi
State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();//TYPE_MOBILE=1
//txtWifi.setText(wifi.toString());
//如果3G网络和wifi网络都未连接,且不是处于正在连接状态 则进入Network Setting界面 由用户配置网络连接
if(mobile==State.CONNECTED||mobile==State.CONNECTING)
{
Toast.makeText(this, "移动网络已开启。", Toast.LENGTH_SHORT).show();
return false;
}
else
{
if(wifi==State.CONNECTED||wifi==State.CONNECTING)
{
Toast.makeText(this, "Wifi已开启。", Toast.LENGTH_SHORT).show();
return false;
}
Toast.makeText(this, "请开启无线网络!", Toast.LENGTH_SHORT).show();
}
Intent tmpIntent=new Intent(Settings.ACTION_WIRELESS_SETTINGS);
startActivityForResult(tmpIntent,0);
return true;
//startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));//进入无线网络配置界面
//startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); //进入手机中的wifi网络设置界面
}
private final String namespace="http://tempuri.org/";
private String URL="http://192.168.10.11:8800/SmartWebService/Service1.asmx";
private String method_name="LoginVertify";
private String soap_action="http://tempuri.org/LoginVertify";
private SoapObject soap;
//private SoapPrimitive soapPri;
private void showContent() {
// TODO Auto-generated method stub
try
{
//AndroidHttpTransport ht=new AndroidHttpTransport(URL);
//HttpPost request=new HttpPost(URL);
EditText tmpUserNameEditText=(EditText)findViewById(R.id.UserName);
//tmpUserNameEditText.setText(Text);
String LoginName=tmpUserNameEditText.getText().toString();
EditText tmpPasswordEditText=(EditText)findViewById(R.id.Password);
String Password=tmpPasswordEditText.getText().toString();
HttpTransportSE ht=new HttpTransportSE(URL);
ht.debug=true;
SoapObject rpc=new SoapObject(namespace, method_name);
if(LoginName!=""&&Password!="")
{
rpc.addProperty("prmUserName", LoginName);
rpc.addProperty("prmUserPassword", Password);
}
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut=ht;
envelope.dotNet=true;
envelope.setOutputSoapObject(rpc);
try
{
ht.call(soap_action, envelope);//运行到此出异常
soap =(SoapObject)envelope.bodyIn;
//Text=envelope.getResponse().toString();
//Log.e("xml", Text);
Intent intent=new Intent();
intent.setClass(Demo.this, Login.class);
LoginVertifyResult=envelope.getResponse().toString();
Bundle tmpbundle=new Bundle();
tmpbundle.putString("LoginName", LoginVertifyResult);
tmpbundle.putString("Password", Password);
intent.putExtras(tmpbundle);
/*
if(LoginVertifyResult=="Success...")
{
}
else
{
Bundle tmpbundle=new Bundle();
tmpbundle.putString("LoginName",LoginVertifyResult);
tmpbundle.putString("Password", "");
intent.putExtras(tmpbundle);
}
*/
startActivity(intent);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
catch (XmlPullParserException e)
//catch(Exception e)
{
e.printStackTrace();
}
}}
配置文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="softdevonline.Demo" android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps"></uses-library>
<activity android:name=".Demo" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Login"></activity>
<activity android:name="GridViewDemo"></activity>
<activity android:name="Listview"></activity>
<activity android:name="ImageViewDemo"></activity>
<activity android:name="MapView"></activity>
</application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<receiver android:name="com.blackboard.androidtest.receiver.ConnectionChangeReceiver"
android:label="NetworkConnection"/>
</manifest>
Console:
[2011-08-02 10:48:01 - Demo] ------------------------------
[2011-08-02 10:48:01 - Demo] Android Launch!
[2011-08-02 10:48:01 - Demo] adb is running normally.
[2011-08-02 10:48:01 - Demo] No Launcher activity found!
[2011-08-02 10:48:01 - Demo] The launch will only sync the application package on the device!
[2011-08-02 10:48:01 - Demo] Performing sync
[2011-08-02 10:48:07 - Demo] Application already deployed. No need to reinstall.
[2011-08-02 10:48:07 - Demo] \Demo\bin\Demo.apk installed on device
[2011-08-02 10:48:07 - Demo] Done!
在运行到对Button的Click事件进行监听时,出现强制关闭。 --------------------编程问答-------------------- No Launcher activity found!
AndroidManifest.xml看看有没问题
看看activity有没注册对 有没加下面这段
--------------------编程问答-------------------- 楼上的加了,还是强制关闭,应该不是这个原因 --------------------编程问答-------------------- 强制关闭的原因多了去了,我的经验是单步执行,肯定是某个地方出错了,没有被代码捕获到或者没有去捕获,才会直接强制关闭。
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
另外,如果涉及硬件环境,那必须确认是否有该硬件,然后是否赋予了访问这个硬件的环境,还有,就是可能涉及网络环境,是否确实满足你的预设要求。 --------------------编程问答-------------------- 网络有允许不,调试信息拿出来瞧瞧
补充:移动开发 , Android