0

I'm having trouble running my Android app in the emulator: I get the same error everytime I try to:

12-12 08:53:33.958: E/cutils-trace(5320): Error opening trace file: No such file or directory (2)

Here is my LoginPage.java code:

EDIT: I changed my .java's code a bit but I keep on getting the above error... I'm sure there's something I'm not fully understanding but I can't see what it is.

LoginPage.java

    package com.example.shop;

    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;

    import org.apache.http.HttpResponse;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;

    import com.example.shop.R;

    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.AdapterView;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.widget.AdapterView.OnItemSelectedListener;

public class LoginPage extends Activity implements OnClickListener, OnItemSelectedListener {

    Context context;
    private TextView textView;
    EditText username;
    EditText password;
    String userid;
    boolean succeed;
    Boolean isInternetPresent; 
    ConnectionChecker cc; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_page);
        context=this;
        userid = "";
        username = (EditText)findViewById(R.id.edittext_login_username);
        password = (EditText)findViewById(R.id.edittext_login_password);
        textView = (TextView)findViewById(R.id.textView);
        cc = new ConnectionChecker(getApplicationContext());
        isInternetPresent = false;
     //login_button();

        Button enter = (Button) findViewById(R.id.enter);
        enter.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            if(arg0.getId() == R.id.enter)
            {
                Toast.makeText(
                        context, 
                        "Login correcte", 
                        Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(context, Tenda.class);
                DownloadWebPageTask task = new DownloadWebPageTask();
                task.execute(new String[] { "http://www.v2msoft.com/clientes/lasalle/curs-android/login.php" });
                startActivity(intent);
                finish();

            }

            if (username.getText().toString().equals("luis") && password.getText().toString().equals("seguro")){
                Toast.makeText(getApplicationContext(), "Redirecting...", 
                          Toast.LENGTH_SHORT).show();
                succeed = true;
                userid = "luis";
            }
            else{
                Toast.makeText(getApplicationContext(), "Wrong info",
                          Toast.LENGTH_SHORT).show();
                succeed = false; 
            }


            }

        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.login_page, menu);
        return true;
    }

    public void login ()
    {

    }

    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }

    private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... urls) {
          String response = "";
          for (String url : urls) {
            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);
            try {
              HttpResponse execute = client.execute(httpGet);
              InputStream content = execute.getEntity().getContent();

              BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
              String s = "";
              while ((s = buffer.readLine()) != null) {
                response += s;
              }

            } catch (Exception e) {
              e.printStackTrace();
            }
          }
          return response;
        }

        @Override
        protected void onPostExecute(String result) {
          textView.setText(result);
        }
      }


    public void login_button()
    {



    }

    public void IC (View v)
    {
        isInternetPresent = cc.isConnectingToInternet();

        // check for Internet status
        if (isInternetPresent) {
            // Internet Connection is Present
            // make HTTP requests
            showAlertDialog(LoginPage.this, "Internet Connection",
                    "You have internet connection", true);
        } else {
            // Internet connection is not present
            // Ask user to connect to Internet
            showAlertDialog(LoginPage.this, "No Internet Connection",
                    "You don't have internet connection.", false);
        }
    }

    @SuppressWarnings("deprecation")
    public void showAlertDialog(Context context, String title, String message, Boolean status) {
            AlertDialog alertDialog = new AlertDialog.Builder(context).create();

            // Setting Dialog Title
            alertDialog.setTitle(title);

            // Setting Dialog Message
            alertDialog.setMessage(message);       

            // Setting OK Button
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                }
            });

            // Showing Alert Message
            alertDialog.show();
        }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

    }

}

And, also, my .xml file:

activity_login_page.xml

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".LoginPage" >

<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
        android:layout_height="wrap_content"

    ></TextView>

    <EditText 
        android:id="@+id/edittext_login_username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp" 
        android:text="username"
        android:inputType="text"/>

    <EditText
        android:id="@+id/edittext_login_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="password"
        android:password="true"
        android:layout_below="@+id/edittext_login_username"
         />

        <Button 
        android:id="@+id/enter"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp" 
        android:layout_gravity="right"
        android:text="login"
        android:layout_below="@+id/edittext_login_password" />

</RelativeLayout>

Anyone could pinpoint to me where my mistake is?

2 Answers 2

2

First move this onCreate() method.

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login_page);
    context=this;

    EditText username = (EditText)findViewById(R.id.edittext_login_username);
    EditText password = (EditText)findViewById(R.id.edittext_login_password);
    login_button();   
 }

Because you can't initialize your UI element before onCreate() method.

Also you have just declare your

private TextView textView;

but not initialize it means didn't find ID for it. So do that also.

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

3 Comments

I see! It was a very elemental mistake, really... But it doesn't change the fact that I get the same error when I try to run it: do I need to fix something else?
Have you download any image or text file from the server?
No. I don't DL anything in this activity. I use the Internet connection to check that the username and password with a server and verify that they're the correct ones.
1

do this first

public class LoginPage extends Activity implements OnClickListener, OnItemSelectedListener {

        Context context;
        private TextView textView;
        EditText username ;
        EditText password ;
        String userid;
        boolean succeed;

        ConnectionChecker cc;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_login_page);
            context=this;
          username = (EditText)findViewById(R.id.edittext_login_username);
        password = (EditText)findViewById(R.id.edittext_login_password);
        String userid = "";

        Boolean isInternetPresent = false;
        ConnectionChecker cc = new ConnectionChecker(getApplicationContext());
         login_button();   
        }


        }

11 Comments

Declare the variables above onCreate and the link your declared variables in onCreate
I've done what you said but I get the same error... Do I need to call for another function below within the onCreate method?
can u share your logcat
and don not call ur function login_button(); try calling it like enter.setOnClickListener(this); i.e in onCreate
Logcat: "12-12 09:24:54.808: E/cutils-trace(5407): Error opening trace file: No such file or directory (2)". And I do the "setOnClickListener" within the "login_button()" function.
|

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.