试图调试简单的Android应用程序(Yamba教程)

时间:2013-12-05 04:28:44

标签: java android eclipse debugging

我一直在学习Android的教程,我完全陷入困境。我的程序由于我找不到的错误而崩溃...这是我的代码。任何人都可以指出我找到正确的方向吗?我的catlog引用了第28行(我在java文件中放置了注释),我已经看过了,但找不到错误或引用错误。

清单

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.yamba"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="14" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application

        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Light">
        <activity
            android:name=".StatusActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

status.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/status_update"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:onClick="onClick"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/button_update" />

    <EditText
        android:id="@+id/edit_status"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="@string/status_hint"
        android:inputType="textMultiLine" />

</LinearLayout>

StatusActivity.java

 package com.example.yamba;

import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.TwitterException;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class StatusActivity extends Activity {
static final String TAG = "StatusActivity";
    EditText editStatus;

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        Log.d(TAG, "onCreated with Bundle" + bundle);
        setContentView(R.layout.status);
        editStatus = (EditText) findViewById(R.id.edit_status);

    }

    public void onClick(View v) {
        String statusText = editStatus.getText().toString();
        new PostToTwitter().execute(statusText);               // Line 28
        Log.d(TAG, "onClicked with Text" + statusText);

    }

    class PostToTwitter extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {
            try {
                Twitter twitter = new Twitter("student", "password");
                twitter.setAPIRootUrl("http://yamba.marakana.com/api");
                twitter.setStatus(params[0]);
                Log.d(TAG, "Successfully Posted:" + params[0]);
                return "Successfully posted:" + params[0];
            } catch (TwitterException e) {
                Log.e(TAG, "Died", e);
                e.printStackTrace();
                return "Failed posting:" + params[0];
            }

        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            Toast.makeText(StatusActivity.this, result, Toast.LENGTH_LONG).show();
        }

    }

}

这是我输入状态并提交

后的catlog
12-03 05:43:56.716: W/dalvikvm(2482): VFY: unable to resolve new-instance 819 (Lwinterwell/jtwitter/Twitter;) in Lcom/example/yamba/StatusActivity$PostToTwitter;
12-03 05:43:56.726: D/dalvikvm(2482): VFY: replacing opcode 0x22 at 0x0001
12-03 05:43:56.726: W/dalvikvm(2482): VFY: unable to resolve exception class 820 (Lwinterwell/jtwitter/TwitterException;)
12-03 05:43:56.736: W/dalvikvm(2482): VFY: unable to find exception handler at addr 0x3f
12-03 05:43:56.736: W/dalvikvm(2482): VFY:  rejected Lcom/example/yamba/StatusActivity$PostToTwitter;.doInBackground ([Ljava/lang/String;)Ljava/lang/String;
12-03 05:43:56.736: W/dalvikvm(2482): VFY:  rejecting opcode 0x0d at 0x003f
12-03 05:43:56.736: W/dalvikvm(2482): VFY:  rejected Lcom/example/yamba/StatusActivity$PostToTwitter;.doInBackground ([Ljava/lang/String;)Ljava/lang/String;
12-03 05:43:56.736: W/dalvikvm(2482): Verifier rejected class Lcom/example/yamba/StatusActivity$PostToTwitter;
12-03 05:43:56.786: D/AndroidRuntime(2482): Shutting down VM
12-03 05:43:56.796: W/dalvikvm(2482): threadid=1: thread exiting with uncaught exception (group=0xb3ad8b90)
12-03 05:43:56.936: E/AndroidRuntime(2482): FATAL EXCEPTION: main
12-03 05:43:56.936: E/AndroidRuntime(2482): Process: com.example.yamba, PID: 2482
12-03 05:43:56.936: E/AndroidRuntime(2482): java.lang.IllegalStateException: Could not execute method of the activity
12-03 05:43:56.936: E/AndroidRuntime(2482):     at android.view.View$1.onClick(View.java:3814)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at android.view.View.performClick(View.java:4424)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at android.view.View$PerformClick.run(View.java:18383)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at android.os.Handler.handleCallback(Handler.java:733)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at android.os.Handler.dispatchMessage(Handler.java:95)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at android.os.Looper.loop(Looper.java:137)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at android.app.ActivityThread.main(ActivityThread.java:4998)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at java.lang.reflect.Method.invokeNative(Native Method)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at java.lang.reflect.Method.invoke(Method.java:515)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at dalvik.system.NativeStart.main(Native Method)
12-03 05:43:56.936: E/AndroidRuntime(2482): Caused by: java.lang.reflect.InvocationTargetException
12-03 05:43:56.936: E/AndroidRuntime(2482):     at java.lang.reflect.Method.invokeNative(Native Method)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at java.lang.reflect.Method.invoke(Method.java:515)
12-03 05:43:56.936: E/AndroidRuntime(2482):     at android.view.View$1.onClick(View.java:3809)
12-03 05:43:56.936: E/AndroidRuntime(2482):     ... 11 more
12-03 05:43:56.936: E/AndroidRuntime(2482): Caused by: java.lang.VerifyError: com/example/yamba/StatusActivity$PostToTwitter
12-03 05:43:56.936: E/AndroidRuntime(2482):     at com.example.yamba.StatusActivity.onClick(StatusActivity.java:28)
12-03 05:43:56.936: E/AndroidRuntime(2482):     ... 14 more

1 个答案:

答案 0 :(得分:0)

将第28行替换为以下行,看看它是否有效

    PostToTwitter object=new PostToTwitter();
object.excute(statusText);

您需要阅读有关异步任务的更多信息