android app在启动时崩溃,Logcat:在/ data / app / [包名]找不到类“[包名]”

时间:2013-07-29 04:18:32

标签: android web-services crash startup logcat

希望你能解决我的问题。我的应用程序在启动时崩溃,所以我尝试使用LogCat来查找错误。如标题中所述,errormassage表示:

07-29 03:49:46.734: E/AndroidRuntime(837): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.calculate.firsttry/com.example.calculate.firsttry.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.calculate.firsttry.MainActivity" on path: /data/app/com.example.calculate.firsttry-1.apk
07-29 03:49:46.734: E/AndroidRuntime(837): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.calculate.firsttry.MainActivity" on path: /data/app/com.example.calculate.firsttry-1.apk

所以好像我错过了某个地方的声明。问题是,我不知道在哪里。这不是我的第一个应用程序,我想我已经重复了之前所做的每一步。

这是我的应用程序的代码:

package com.example.calculate.firsttry;

 import org.ksoap2.SoapEnvelope;
 import org.ksoap2.serialization.SoapObject;
 import org.ksoap2.serialization.SoapSerializationEnvelope;
 import org.ksoap2.transport.HttpTransportSE;import android.app.Activity;
 import android.os.Bundle;
 import android.widget.TextView;

 public class AndroidWSDLFrontEnd extends Activity {

 private String METHOD_NAME = "add"; // our webservice method name
 private String NAMESPACE = "http://calculator.backend.org";;
 private String SOAP_ACTION = NAMESPACE + METHOD_NAME; // NAMESPACE + method name
 private static final String URL = "http://10.35.108.154:8080/AndroidBackend/services/Calculator?wsdl";;// you must use ipaddress here, don’t use Hostname or localhost

/** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

TextView tv = (TextView) findViewById(R.id.txtAddition);
 try
 {
 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
 request.addProperty("a", 5);
 request.addProperty("b", 15);
 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
 envelope.dotNet = true;
 envelope.setOutputSoapObject(request);
 HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
 androidHttpTransport.call(SOAP_ACTION,envelope);
 Object result = envelope.getResponse();
 System.out.println("Result: " + result.toString());
 ((TextView) findViewById (R.id.txtAddition)).setText("Addition :" +result.toString());
 } catch (Exception E) {
 E.printStackTrace();
 ((TextView) findViewById (R.id.txtAddition)).setText("ERROR: "    + E.getClass().getName() + "," + E.getMessage());
 }
 }
 }

也许我在这里错过了什么。我不能再指出这个问题了。我得到的只是代码和错误信息。那么如何让我的应用程序运行?

感谢您的帮助。

3 个答案:

答案 0 :(得分:3)

一些建议

1)如果尚未声明,则在AndroidManifest.xml文件中声明活动。

2)您似乎正在尝试打开MainActivity class/Activity,并在问题中添加了AndroidWSDLFrontEnd个活动,希望您调用正确的Activity,检查Manifest中相应类的名称/ ActivityDeclararion并在开始活动时。

07-29 03:49:46.734: E/AndroidRuntime(837): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.calculate.firsttry.**MainActivity**" // here it says MainActivity not found, Check the name of your activity

答案 1 :(得分:1)

AndroidManifest.xml

尝试更改

 <activity
        android:name="com.example.calculate.firsttry.MainActivity"
        ............

    </activity>

 <activity
            android:name="com.example.calculate.firsttry.AndroidWSDLFrontEnd"
            ............

        </activity>

答案 2 :(得分:1)

我在Android Studio 0.2.10中遇到此问题,并且必须在Android Studio中执行Gradle clean