在模拟器上运行时出错

时间:2014-04-02 07:50:02

标签: java android xml

我的应用没有错误行,但是当我在模拟器上运行时,它出现错误the application Koperasidb (process.com.randy.koperasidb) has stopped unexpectedly Please try again请帮忙,这里是我的login.java代码:

package com.randy.koperasidb;

import android.app.Activity;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
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;


import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class login extends Activity implements OnClickListener{
    EditText kode,pw;
    TextView error;
    Button login;
    String i;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        kode = (EditText) findViewById(R.id.kode);
        pw = (EditText) findViewById (R.id.password);
        login = (Button) findViewById (R.id.login);
        error = (EditText) findViewById (R.id.error);
        login.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        switch(v.getId()){
        case R.id.login:
            insert();
        }
    } 
    public void insert(){
        String i= "http://10.0.2.2/mysql/insert.php";
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(i);
        ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
        param.add(new BasicNameValuePair("kode", kode.getText().toString()));
        param.add(new BasicNameValuePair("password", pw.getText().toString()));

        try {
            httpPost.setEntity(new UrlEncodedFormEntity(param));
            HttpResponse httpRespose = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpRespose.getEntity();
            InputStream in = httpEntity.getContent();
            BufferedReader read = new BufferedReader(new InputStreamReader(in));

            String isi= "";
            String baris= "";

            while((baris = read.readLine())!=null){
                isi+= baris;
            }
            if(!isi.equals("null")){
                Toast.makeText(this, "Berhasil", Toast.LENGTH_LONG).show();
            }else{
                Toast.makeText(this, "Gagal", Toast.LENGTH_LONG).show();
            }

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }           

} 

这是我的login.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff00ffff"
    >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:text="Selamat datang di Puskopdit Jakarta"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#ff0000ff"
/>
<TextView
    android:text="Input Kode Anggota"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#ff0000ff"
/>
<EditText
    android:id="@+id/kode"
    android:layout_width="150px"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_gravity="center"
    android:hint="Kode Anggota"
/>
<TextView
    android:text="Input Password"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#ff0000ff"
/>
<EditText
    android:id="@+id/password"
    android:layout_width="150px"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_gravity="center"
    android:hint="Password"
/>
<Button
    android:id="@+id/login"
    android:layout_width="200px"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_gravity="center"
    android:textColor="#ffffffff"
/>
<TextView
    android:text=""
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#ff0000ff"
    android:id="@+id/error"
/>
</TableLayout>
</LinearLayout>

这是我的AndroidManifest.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.randy.koperasidb"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".login"
                  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>
    <uses-sdk android:minSdkVersion="9" />
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest> 

0 个答案:

没有答案