Friday, 3 April 2015

FATAL EXCEPTION: Unable to start activity ComponentInfo - Android



My problem is that when I run my app on the android emulator, the start is ok, but, when I press the login button : "Unfortunately, confession has stopped." the other button (singup) works ok. in the end my log fail code.


Thanks very much for the help.


Here my code.


LoginActivity.java



package com.tinkerdevelop.secretos;



import com.google.android.gcm.GCMRegistrar;
import com.provenlogic.confession.Util.JSONObjects;
import com.provenlogic.confession.Util.SessionManager;
import com.provenlogic.confession.Util.Url;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends Activity implements OnClickListener {

EditText edit_text_login_email;
EditText edit_text_login_Password;
Button button_login;
TextView signup;
// Session Manager Class
SessionManager session;

String email;
String password;
String uid;


//GPSTracker gps;
InputMethodManager imm;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_login);




// Session Manager
session = new SessionManager(getApplicationContext());
imm= (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
/* gps = new GPSTracker(LoginActivity.this);

// check if GPS enabled
if(gps.canGetLocation()){

double latitude = gps.getLatitude();
double longitude = gps.getLongitude();

// \n is for new line
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}else{
// can't get location
// GPS or Network is not enabled
// Ask user to enable GPS/network in settings
gps.showSettingsAlert();
}

*/


//double location[]=new GetLatAndLong().storeLongLat(getApplicationContext());

//Toast.makeText(getApplicationContext(), "Latitude "+location[0]+" long "+location[1], Toast.LENGTH_LONG).show();

if (session.isLoggedIn()) {

// Staring MainActivity
Intent i = new Intent(getApplicationContext(), ConfessionActivity.class);
startActivity(i);
finish();

}

GCMRegistrar.checkDevice(this);

// Make sure the manifest was properly set - comment out this line
// while developing the app, then uncomment it when it's ready.
GCMRegistrar.checkManifest(this);
GCMRegistrar.register(this, Url.Gcm.SENDER_ID);
// Get GCM registration id
widgets();
}

private void widgets() {
// TODO Auto-generated method stub

edit_text_login_email = (EditText) findViewById(R.id.edit_text_login_email);
edit_text_login_Password = (EditText) findViewById(R.id.edit_text_login_Password);
button_login = (Button) findViewById(R.id.button_login);
button_login.setOnClickListener(this);

signup=(TextView) findViewById(R.id.signup);
signup.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// Staring MainActivity
Intent i = new Intent(getApplicationContext(),
SignUp.class);
startActivity(i);
finish();

}
});

}

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

@Override
public void onBackPressed() {
startActivity(new Intent(this,LaunchActivity.class));

}

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

final ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();


email = edit_text_login_email.getText().toString();
password = edit_text_login_Password.getText().toString();
imm.hideSoftInputFromWindow(edit_text_login_Password.getWindowToken(), 0);

if (email.trim().length() > 0) {

if (password.trim().length() > 0) {
//GCMRegistrar.register(this, Url.Gcm.SENDER_ID);

final String regId = GCMRegistrar.getRegistrationId(this);

// Check if regid already presents
if (!regId.equals("")) {
// Registration is not present, register now with GCM

//Toast.makeText(getBaseContext(), "Registering ", Toast.LENGTH_SHORT).show();

pDialog.hide();
new GetAuth().execute(email, password,regId);
}else{
pDialog.hide();
GCMRegistrar.register(this, Url.Gcm.SENDER_ID);
}
} else {

pDialog.hide();
Toast.makeText(getApplicationContext(), "Enter Password",
Toast.LENGTH_LONG).show();
}

} else {

pDialog.hide();
Toast.makeText(getApplicationContext(), "Enter UserName",
Toast.LENGTH_LONG).show();
}

}

public class GetAuth extends AsyncTask<String, String, String> {
Dialog progress;

@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub

String[] data = new String[3];
data[0] = arg0[0];
data[1] = arg0[1];
data[2] = arg0[2];

JSONObjects js = new JSONObjects();
// js.sava_user_on_server(getApplicationContext(), data);
return js.GetUserAuth(getApplicationContext(), data);
}

@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
progress = ProgressDialog.show(LoginActivity.this, "",
"Please wait...");
}

@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
button_login.setVisibility(View.VISIBLE);
String[] login=result.split("[-]");

if (login[0].equals("true")) {

session.createLoginSession(email,login[1]);

// Staring MainActivity
Intent i = new Intent(getApplicationContext(),
ConfessionActivity.class);
startActivity(i);

finish();

} else {

button_login.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(), "" + result,
Toast.LENGTH_LONG).show();

}

progress.dismiss();

}

}

}


activity_login.xml



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dip">


<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Email"
android:singleLine="true"
android:layout_marginBottom="5dip"/>


<EditText android:id="@+id/edit_text_login_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"/>

<!-- Password Label -->

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="ContraseƱa" />

<!-- Password input text -->
<EditText android:id="@+id/edit_text_login_Password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:password="true"
android:singleLine="true"/>

<!-- Login button -->

<Button
android:id="@+id/button_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="Entrar" />

<!-- <Button
android:id="@+id/signup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="#98FF98"

android:text="Sign Up"
/>
-->

<TextView
android:id="@+id/signup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dip"
android:layout_marginTop="18dip"
android:padding="7dp"
android:text="No tengo una cuenta " />

</LinearLayout>


AndroidManifest.xml



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="com.tinkerdevelop.secretos"
android:versionCode="2"
android:versionName="1.1" >

<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Creates a custom permission so only this app can receive its messages. -->
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<permission
android:name="com.provenlogic.confession.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

<uses-permission android:name="com.provenlogic.confession.C2D_MESSAGE" />

<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<!-- Network State Permissions to detect Internet status -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Permission to vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />

<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher_secretos"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<activity
android:name="com.tinkerdevelop.secretos.LaunchActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<activity
android:name="com.tinkerdevelop.secretos.LoginActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>

<activity
android:name="com.tinkerdevelop.secretos.ConfessionActivity"
android:label="@string/title_activity_confession"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.tinkerdevelop.secretos.ComposeMessage"
android:label="@string/title_activity_compose_message"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.tinkerdevelop.secretos.Notification"
android:label="@string/title_activity_notification"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.tinkerdevelop.secretos.ExploreActivity"
android:label="@string/title_activity_explore"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.tinkerdevelop.secretos.Settings"
android:label="@string/title_activity_settings"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.provenlogic.confession.NewMessagePanel"
android:label="@string/title_activity_settings"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.tinkerdevelop.secretos.NewMessage"
android:label="@string/title_activity_new_message"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.tinkerdevelop.secretos.ChangePassword"
android:label="@string/title_activity_change_password"
android:screenOrientation="portrait" >
</activity>

<activity
android:name="com.tinkerdevelop.secretos.SignUp"
android:label="@string/title_activity_sign_up"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.tinkerdevelop.secretos.CheckNewFriends"
android:label="@string/title_activity_check_new_friends"
android:screenOrientation="portrait" >
</activity>

<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>

<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

<category android:name="com.provenlogic.confession" />
</intent-filter>
</receiver>

<service android:name="com.tinkerdevelop.secretos.GCMIntentService" />

<activity
android:name="com.tinkerdevelop.secretos.TermsAndConditions"
android:label="@string/title_activity_terms_and_conditions" >
</activity>
<activity
android:name="com.tinkerdevelop.secretos.NewPostByFriends"
android:label="@string/title_activity_new_post_by_friends" >
</activity>
<activity
android:name="com.provenlogic.confession.Test1Activity"
android:label="@string/title_activity_test1" >
</activity>
</application>

</manifest>


SingUp.java



package com.tinkerdevelop.secretos;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import com.provenlogic.confession.Util.GPSTracker;
import com.provenlogic.confession.Util.JSONObjects;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.view.Menu;
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 SignUp extends Activity implements OnClickListener {

EditText edit_text_sign_up_user_phone_number;
EditText edit_text_sign_up_Email;
EditText edit_text_signup_Password;
EditText edit_text_signup_retype_password;
Button button_signup;

String phone;
String email;
String password;
String retype_password;

TextView signup;
GPSTracker gps;
double latitude ;
double longitude;
String CountryID;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);

// Make sure the device has the proper dependencies.
/*GCMRegistrar.checkDevice(this);

// Make sure the manifest was properly set - comment out this line
// while developing the app, then uncomment it when it's ready.
GCMRegistrar.checkManifest(this);
// Get GCM registration id
*/
TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
//getNetworkCountryIso
CountryID= manager.getSimCountryIso().toUpperCase();

//GCMRegistrar.register(this, Url.Gcm.SENDER_ID);



gps = new GPSTracker(SignUp.this);

// check if GPS enabled
if(gps.canGetLocation()){

latitude = gps.getLatitude();
longitude = gps.getLongitude();

// \n is for new line
//Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}

widgets();
}

private void widgets() {
// TODO Auto-generated method stub

edit_text_sign_up_user_phone_number = (EditText) findViewById(R.id.edit_text_sign_up_user_phone_number);
edit_text_sign_up_Email = (EditText) findViewById(R.id.edit_text_sign_up_Email);

edit_text_signup_Password = (EditText) findViewById(R.id.edit_text_signup_Password);

edit_text_signup_retype_password = (EditText) findViewById(R.id.edit_text_signup_retype_password);

button_signup = (Button) findViewById(R.id.button_signup);
button_signup.setOnClickListener(this);



}

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

@Override
public void onBackPressed() {
startActivity(new Intent(this,LaunchActivity.class));

}

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
phone = edit_text_sign_up_user_phone_number.getText().toString();
email = edit_text_sign_up_Email.getText().toString();
password = edit_text_signup_Password.getText().toString();
retype_password = edit_text_signup_retype_password.getText().toString();

/*private void storeLongLat() {
// TODO Auto-generated method stub
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location!=null) {
longitude = location.getLongitude();
latitude = location.getLatitude();
} else {

}


}*/


if (phone.length() > 0 && formatPhoneNumber(phone) != null) {

if (email.length() > 0 && validateEmail(email)) {

if (password.length() > 0) {

if (password.equals(retype_password)) {



/*final String regId = GCMRegistrar.getRegistrationId(this);

// Check if regid already presents
if (regId.equals("")) {
// Registration is not present, register now with GCM

Toast.makeText(getBaseContext(), "Registering ", Toast.LENGTH_SHORT).show();

} else {*/

SaveDataOnServer SaveDataOnServer = new SaveDataOnServer();
SaveDataOnServer.execute(formatPhoneNumber(phone), email, password);

//Toast.makeText(getBaseContext(), ""+regId, Toast.LENGTH_SHORT).show();

// }


} else {

Toast.makeText(getApplicationContext(),
"Password mismatch", Toast.LENGTH_LONG).show();

}

} else {

Toast.makeText(getApplicationContext(), "Enter Password",
Toast.LENGTH_LONG).show();

}

} else {
Toast.makeText(getApplicationContext(), "Enter Valid Email",
Toast.LENGTH_LONG).show();

}
} else {
Toast.makeText(getApplicationContext(), "We could not verify your cellular network.\nPlease try again.",
Toast.LENGTH_LONG).show();

}

}

public class SaveDataOnServer extends AsyncTask<String, String, String> {
//Dialog progress;

@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub


// Toast.makeText(getApplicationContext(), " "+regId , Toast.LENGTH_LONG).show();
String[] data = new String[4];
data[0] = arg0[0];
data[1] = arg0[1];
data[2] = arg0[2];
//data[3] = arg0[3];
//data[3] = regId;
JSONObjects js = new JSONObjects();
// js.sava_user_on_server(getApplicationContext(), data);
return js.sava_user_on_server(getApplicationContext(), data,longitude,latitude);




}

@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
//progress = ProgressDialog.show(SignUp.this, "", "Please wait...");
}

@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);

if (result.equals("true")) {

Toast.makeText(getApplicationContext(), "Signed up successfully.",
Toast.LENGTH_LONG).show();
// Staring MainActivity
Intent i = new Intent(getApplicationContext(),
LoginActivity.class);
startActivity(i);
finish();
} else {

Toast.makeText(getApplicationContext(), "" + result,
Toast.LENGTH_LONG).show();

}

//progress.dismiss();


}

}

public boolean validateEmail(String email) {

Pattern pattern;
Matcher matcher;
String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
pattern = Pattern.compile(EMAIL_PATTERN);
matcher = pattern.matcher(email);
return matcher.matches();

}

public String formatPhoneNumber(String phoneNumber){

PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
PhoneNumber NumberProto = null;
String formattedPhone = null;


if (phoneNumber.matches(".*[a-zA-Z].*")){
formattedPhone = null;
} else {
try {

NumberProto = phoneUtil.parse(phoneNumber, "IN");
formattedPhone = phoneUtil.format(NumberProto, PhoneNumberFormat.E164);
formattedPhone = formattedPhone.substring(1);
} catch (NumberParseException e) {
System.err.println("NumberParseException was thrown: " + e.toString());
}

}

return formattedPhone;

}



}


activity_sing_up.xml



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dip">


<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/phone"
android:singleLine="true"
android:layout_marginBottom="5dip"/>

<!-- Username input text -->
<EditText android:id="@+id/edit_text_sign_up_user_phone_number"
android:inputType="phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/phone"
android:layout_marginBottom="10dip"/>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/email"
android:singleLine="true"
android:layout_marginBottom="5dip"/>

<!-- Email input text -->
<EditText android:id="@+id/edit_text_sign_up_Email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="@string/email"
android:layout_marginBottom="10dip"/>


<!-- Password Label -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/password"
android:layout_marginBottom="5dip"/>

<!-- Password input text -->
<EditText android:id="@+id/edit_text_signup_Password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:inputType="textPassword"
android:hint="@string/password"
android:singleLine="true"/>

<!-- Password Label -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/retypepassword"
android:layout_marginBottom="5dip"/>

<!-- Password input text -->
<EditText android:id="@+id/edit_text_signup_retype_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:hint="@string/retypepassword"
android:inputType="textPassword"
android:singleLine="true"/>

<!-- signup button -->
<Button android:id="@+id/button_signup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/signup"/>

</LinearLayout>


Logfile.txt



04-03 10:49:18.630: E/AndroidRuntime(1616): FATAL EXCEPTION: main
04-03 10:49:18.630: E/AndroidRuntime(1616): Process: com.tinkerdevelop.secretos, PID: 1616
04-03 10:49:18.630: E/AndroidRuntime(1616): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tinkerdevelop.secretos/com.tinkerdevelop.secretos.LoginActivity}: java.lang.IllegalStateException: Application does not define permission com.tinkerdevelop.secretos.permission.C2D_MESSAGE

No comments:

Post a Comment