android错误来运行项目

时间:2014-08-22 06:12:04

标签: java android xml

  1. 在以下期间发生内部错误:"启动New_configuration"。
  2. java.lang.StackOverflowError的。
  3. 你知道如何解决
  4. 我从1页传到另一页。
  5. 是否提供选项退出工作台。
  6. 我也可以发送我的清单文件

    package com.exam.reg_log;
    import java.io.BufferedReader;
    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.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 org.json.JSONObject;
    
    
    
    import android.support.v7.app.ActionBarActivity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.os.StrictMode;
    import android.util.Log;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
    
    
    public class MainActivity extends ActionBarActivity {
    
    
        String name;
        String phn;
        String email;
        String pass;
        InputStream is=null;
        String result=null;
        String line=null;
        int code;
        Button insert,login;
        final Context context = this;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy); 
    
            final EditText e_name=(EditText) findViewById(R.id.editText1);
            final EditText e_phn=(EditText) findViewById(R.id.editText2);
            final EditText e_email=(EditText) findViewById(R.id.editText3);
            final EditText e_pass=(EditText) findViewById(R.id.editText4);
            insert=(Button) findViewById(R.id.button1);
            login = (Button) findViewById(R.id.button2);
    
            login.setOnClickListener(new View.OnClickListener() {
    
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
    
                    Intent intent = new Intent(context, Login.class);
                    startActivity(intent);
    
                }
            });
            insert.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
    
                    name = e_name.getText().toString();
                    phn = e_phn.getText().toString();
                    email = e_email.getText().toString();
                    pass = e_pass.getText().toString();
    
                    insert();
    
                }
            });
        }
        public void insert()
        {
    
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://10.0.2.2/reg_and/insert.php"); 
            try
            {
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    
                nameValuePairs.add(new BasicNameValuePair("name",name));
                nameValuePairs.add(new BasicNameValuePair("phn",phn));
                nameValuePairs.add(new BasicNameValuePair("email",email));
                nameValuePairs.add(new BasicNameValuePair("pass",pass));
                Log.d("smit output",name + phn + email + pass);
                //HttpClient httpclient = new DefaultHttpClient();
               // HttpPost httppost = new HttpPost("http://10.0.2.2/insert.php");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost); 
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
                Log.e("pass 1", "connection success ");
        }
            catch(Exception e)
        {
                Log.e("Fail 1", e.toString());
                Toast.makeText(getApplicationContext(), "Invalid IP Address",
                Toast.LENGTH_LONG).show();
        }     
    
            try
            {
                BufferedReader reader = new BufferedReader
                (new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                while ((line = reader.readLine()) != null)
            {
                    sb.append(line + "\n");
            }
                is.close();
                result = sb.toString();
            Log.e("pass 2", "connection success ");
        }
            catch(Exception e)
        {
                Log.e("Fail 2", e.toString());
        }     
    
        try
        {
            /*
             *  JSONArray jArray = new JSONArray(result);
               for(int i=0;i<jArray.length();i++){
                    JSONObject json_data = jArray.getJSONObject(i);
                    Log.i("log_tag","uID: "+json_data.getInt("uID")+
                            ", uName: "+json_data.getString("uName")+
                            ", uPass: "+json_data.getString("uPass")
                    );
            }
             */
                Log.d("smit output",result);
                JSONObject json_data = new JSONObject(result);
              /*  for(int i=0;i<json_data.length();i++){
                     JSONObject json_data1 = json_data.getJSONObject(i);
                     Log.i("log_tag","uID: "+json_data1.getInt("id")+
                             ", uName: "+json_data1.getString("name")+
                             ", uphn: "+json_data1.getString("phn") +
                             ", uemail: "+json_data1.getString("email") +
                             ", upass: "+json_data1.getString("pass") 
    
                     );
                }*/ 
                code=(json_data.getInt("code"));
    
                if(code==1)
                {
            Toast.makeText(getBaseContext(), "Inserted Successfully",
                Toast.LENGTH_SHORT).show();
                }
                else
                {
             Toast.makeText(getBaseContext(), "Sorry, Try Again",
                Toast.LENGTH_LONG).show();
                }
        }
        catch(Exception e)
        {
                Log.e("Fail 3", e.toString());
        }
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }
        }
    
    // menifest file ......................
    
    <?xml version="1.0" encoding="utf-8"?>
    

    <uses-permission android:name="android.permission.INTERNET" />
    
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Login"
            android:label="@string/title_activity_login" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
    

0 个答案:

没有答案