0

I'm trying to insert data mysql server but when i run my apps. It straight away force close. Need help in the coding. I have put my logcat txt file below. DO help me take a look what went wrong. Thanks.

logcat.txt

05-06 04:23:35.294: E/Trace(837): error opening trace file: No such file or directory (2)
05-06 04:23:36.744: D/dalvikvm(837): GC_FOR_ALLOC freed 59K, 2% free 10795K/11011K, paused 128ms, total 130ms
05-06 04:23:36.824: I/dalvikvm-heap(837): Grow heap (frag case) to 16.065MB for 5760016-byte allocation
05-06 04:23:36.934: D/dalvikvm(837): GC_CONCURRENT freed <1K, 2% free 16420K/16647K, paused 43ms+17ms, total 106ms
05-06 04:23:37.484: D/AndroidRuntime(837): Shutting down VM
05-06 04:23:37.484: W/dalvikvm(837): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
05-06 04:23:37.504: E/AndroidRuntime(837): FATAL EXCEPTION: main
05-06 04:23:37.504: E/AndroidRuntime(837): java.lang.RuntimeException: Unable to start activity ComponentInfo{mp.memberuse/mp.memberuse.LoginRegister}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.os.Looper.loop(Looper.java:137)
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.app.ActivityThread.main(ActivityThread.java:4745)
05-06 04:23:37.504: E/AndroidRuntime(837):  at java.lang.reflect.Method.invokeNative(Native Method)
05-06 04:23:37.504: E/AndroidRuntime(837):  at java.lang.reflect.Method.invoke(Method.java:511)
05-06 04:23:37.504: E/AndroidRuntime(837):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-06 04:23:37.504: E/AndroidRuntime(837):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-06 04:23:37.504: E/AndroidRuntime(837):  at dalvik.system.NativeStart.main(Native Method)
05-06 04:23:37.504: E/AndroidRuntime(837): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.app.ListActivity.onContentChanged(ListActivity.java:243)
05-06 04:23:37.504: E/AndroidRuntime(837):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:259)
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.app.Activity.setContentView(Activity.java:1867)
05-06 04:23:37.504: E/AndroidRuntime(837):  at mp.memberuse.LoginRegister.onCreate(LoginRegister.java:46)
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.app.Activity.performCreate(Activity.java:5008)
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-06 04:23:37.504: E/AndroidRuntime(837):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
05-06 04:23:37.504: E/AndroidRuntime(837):  ... 11 more
05-06 04:23:40.334: I/Process(837): Sending signal. PID: 837 SIG: 9

LoginRegister.java

package mp.memberuse;

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.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.provider.Settings.NameValueTable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class LoginRegister extends ListActivity {

Button btn1, btn2, btn3;
EditText tf1, tf2, tf3, tf4, tf5, tf6, tf7, tf8, tf9, tf10, tf11;
TextView tv1, tv2;
SQLiteDatabase db;

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

    TabHost tabs = (TabHost) this.findViewById(R.id.lt2tabhost);
    tabs.setup();

    TabSpec ts1 = tabs.newTabSpec("Login");
    ts1.setIndicator("Login");
    ts1.setContent(R.id.c1);
    tabs.addTab(ts1);

    TabSpec ts2 = tabs.newTabSpec("Register");
    ts2.setIndicator("Register");
    ts2.setContent(R.id.c2);
    tabs.addTab(ts2);

    btn1 = (Button)findViewById(R.id.button1);
    btn2 = (Button)findViewById(R.id.button2);
    btn3 = (Button)findViewById(R.id.button3);

    tf1=(EditText) findViewById(R.id.editText1);
    tf2=(EditText) findViewById(R.id.editText2);
    tf3=(EditText) findViewById(R.id.editText3);
    tf4=(EditText) findViewById(R.id.editText4);
    tf5=(EditText) findViewById(R.id.editText5);
    tf6=(EditText) findViewById(R.id.editText6);
    tf7=(EditText) findViewById(R.id.editText7);
    tf8=(EditText) findViewById(R.id.editText8);
    tf9=(EditText) findViewById(R.id.editText9);
    tf10=(EditText) findViewById(R.id.editText10);

    tv1=(TextView) findViewById(R.id.login);
    tv2=(TextView) findViewById(R.id.register);



    btn1.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v)
        {
            String username, password;
            username = tf1.getText().toString();
            password = tf2.getText().toString();

            /**try
            {
                String sql="select * from Members;";
                Cursor c1= db.rawQuery(sql, new String[]{});
                String sqlusername, sqlpassword, fullname;


                while(c1.moveToNext())
                {
                    sqlusername = c1.getString(0);
                    sqlpassword = c1.getString(1);
                    fullname = c1.getString(2);

                    if(username.equals(sqlusername) && password.equals(sqlpassword))
                    {
                        SharedPreferences prefs = getSharedPreferences("myPreferences",Context.MODE_PRIVATE);
                        SharedPreferences.Editor editor = prefs.edit();
                        editor.putString("fullname", fullname);
                        editor.commit();

                        Intent intent = new Intent(LoginRegister.this, SendMessage.class);
                        startActivity(intent);
                    }
                    else
                    {
                        tv1.setText("Invalid user");
                    }
                }
            }
            catch(Exception e)
            {
            }**/
        }
    });

    btn2.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v)
        {
            String username, password, cpassword, fullname, nric, address, phone, email;
            username = tf3.getText().toString();
            password = tf4.getText().toString();
            cpassword = tf5.getText().toString();
            fullname = tf6.getText().toString();
            nric = tf7.getText().toString();
            address = tf8.getText().toString();
            phone = tf9.getText().toString();
            email = tf10.getText().toString();

            if(!password.equals(cpassword))
            {
                tv2.setText("Password & Confirm Password does not match.");
            }
            else if(username.equals("") || password.equals("") || cpassword.equals("") || fullname.equals("") || nric.equals("") || address.equals("") || phone.equals("") || email.equals(""))
            {
                tv2.setText("Do not leave any field empty.");
            }
            else
            {
                InputStream is = null;
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();       
                nameValuePairs.add(new BasicNameValuePair("username",username));
                nameValuePairs.add(new BasicNameValuePair("password",password));
                nameValuePairs.add(new BasicNameValuePair("fullname",fullname));
                nameValuePairs.add(new BasicNameValuePair("nric",nric));
                nameValuePairs.add(new BasicNameValuePair("address",address));
                nameValuePairs.add(new BasicNameValuePair("phone",phone));
                nameValuePairs.add(new BasicNameValuePair("email",email));

                try
                {
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost("http://localhost:81/Connections.php");
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
                    is = entity.getContent();
                }
                catch(Exception e)
                {
                    Log.e("log_tag", "Error in http connection"+e.toString());
                }
                    tv2.setText("Register Complete.");
                    tf3.setText("");
                    tf4.setText("");
                    tf5.setText("");
                    tf6.setText("");
                    tf7.setText("");
                    tf8.setText("");
                    tf9.setText("");
                    tf10.setText(""); 
            }
        }
    });

    btn3.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v)
        {
            tf3.setText("");
            tf4.setText("");
            tf5.setText("");
            tf6.setText("");
            tf7.setText("");
            tf8.setText("");
            tf9.setText("");
            tf10.setText("");           
        }
    });
}
}

PHP Code

    <?php

    $hostname_localhost ="localhost";
    $database_localhost ="members";
    $username_localhost ="root";
    $password_localhost ="";

    mysql_connect($hostname_localhost,$username_localhost,$password_localhost);


mysql_select_db("members");

$sql=mysql_query("INSERT INTO members(Username, Password, Fullname, NRIC, Address, Phone, Email)
        VALUES('".$_POST['username']."', '".$_POST['password']."', '".$_POST['fullname']."', '".$_POST['nric']."', '".$_POST['address']."', '".$_POST['phone']."', '".$_POST['email']."')");

$r=mysql_query($sql);

if(!$r)

    echo "Error in query: ".mysql_error();

mysql_close();
    ?>
1
  • Post your xml layout. Is there a ListView there called "list?" Commented May 6, 2013 at 4:36

2 Answers 2

1

as in Log:

Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

means you will need to declare ListView id to android:id="@+id/android:list" in xml layout.

Sign up to request clarification or add additional context in comments.

Comments

1

You have to use this IP address 10.0.2.2 for connecting to localhost

new HttpPost("http://localhost:81/Connections.php");

should be

new HttpPost("http://10.0.2.2:81/Connections.php");

Documentation

5 Comments

I changed it. now it working but no data insert into db when i check.
@JasonAJXiang Show your code for inserting data in mysql in question.
@JasonAJXiang you have done two times mysql_query remove second one.
I removed the second mysql_query but it still dont insert data into db
05-06 06:33:50.084: E/log_tag(1197): Error in http connectionandroid.os.NetworkOnMainThreadException

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.