0

好的,已经卡在这个上很长一段时间了。不是 Java 专家,但一直在尝试创建一个应用程序来简单地将信息发布到 URL。不知道我的代码哪里出错了?请你看看和建议?抱歉上传大量代码真的不知道如何解释它,因为我不知道我哪里出错了。控制台没有错误,模拟器只是无法完全加载应用程序?

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.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;


public class test {


public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("id", "name"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        httpclient.execute(httppost);

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}

  }

   <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <EditText
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="72dp"
    android:layout_marginTop="36dp"
    android:ems="10"
    android:inputType="text"
    android:text="@string/Enter_name" >


       <Button
    android:id="@+id/Submit_Transaction"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="40dp"
    android:layout_toRightOf="@+id/textView1"
    android:onClick="postData()"
    android:text="@string/Submit_Tran_Button" />

    <activity
        android:name="com.testing.myappname.PostData"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

LogCat 以 FATAL EXCEPTION MAIN 错误开始,然后...

01-21 21:52:44.459: E/AndroidRuntime(1155): java.lang.RuntimeException: 无法实例化活动 ComponentInfo{com.test.testing/com.testing.testing.PostData}: java.lang.ClassNotFoundException: 没有在路径上找不到类“com.testing.testingvt.PostData”:/data/app/com.testing.testingvt-1.apk

4

1 回答 1

0

好的。这里的问题是你应该有一个有效的 Activity 类来显示你的 UI。只需阅读此链接上的活动。

于 2013-01-21T22:45:42.403 回答