2

希望你能帮助我解决我的问题。我的应用程序在启动时崩溃,所以我尝试使用 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());
 }
 }
 }

也许我在这里错过了一些东西。我不能再指定问题了。我得到的只是代码和错误消息。那么如何让我的应用程序运行呢?

谢谢你的帮助。

4

3 回答 3

3

一些建议

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

2)您似乎正在尝试打开MainActivity class/Activity并在问题中添加了AndroidWSDLFrontEnd活动,希望您正在调用正确的活动,检查清单/活动声明中各个类的名称以及在开始活动时。

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
于 2013-07-29T04:24:37.047 回答
1

在你的AndroidManifest.xml

尝试改变

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

    </activity>

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

        </activity>
于 2013-07-29T04:27:11.680 回答
1

我在 Android Studio 0.2.10 中遇到了这个问题,不得不在 Android Studio 中执行 Gradle clean

于 2013-09-27T20:14:11.893 回答