I am creating an android app containing a login and after login page , I have given access to Google Maps. When I tried running google maps first without login maps, it worked fine but when I introduced a login page in it theres an error " Unfortunately the app has stopped"
Heres my Main_activity.java
package com.example.maps;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParserException;
import android.support.v7.app.ActionBarActivity;
import android.text.InputType;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ToggleButton;
public class MainActivity extends ActionBarActivity {
Button chkcmd ;
EditText id;
EditText password;
ToggleButton passTog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
chkcmd = (Button) findViewById(R.id.bLOGIN);
id = (EditText) findViewById(R.id.etID);
password = (EditText) findViewById(R.id.etPASSWORD);
passTog = (ToggleButton) findViewById(R.id.tbCHECK);
passTog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(passTog.isChecked()){
password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
id.setInputType(InputType.TYPE_CLASS_TEXT);
}
else{
password.setInputType(InputType.TYPE_CLASS_TEXT);
id.setInputType(InputType.TYPE_CLASS_TEXT);
}
}
});
chkcmd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String checkID = id.getText().toString();
String checkPASS = password.getText().toString();
if(checkID.contentEquals("raubid") && checkPASS.contentEquals("helpme") ){
Intent openStartingPoint = new Intent("com.example.goon.Maps");
startActivity(openStartingPoint);
}
else {
AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(MainActivity.this);
// Setting Dialog Title
alertDialog2.setTitle("Error");
// Setting Dialog Message
alertDialog2.setMessage("Invalid Login Details");
alertDialog2.setNeutralButton("Close", null).show();
}
}
});
}
@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);
}
}
here is my Maps.java
package com.example.maps;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class Maps extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
My login.xml
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
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="com.example.locateme.MainActivity" >
<EditText
android:id="@+id/etID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Device Id"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:password="true" />
<EditText
android:id="@+id/etPASSWORD"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Device Password"
android:layout_gravity="center"
android:layout_marginTop="70dp"
android:password="true" />
<Button
android:id="@+id/bLOGIN"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etCommands"
android:layout_below="@+id/etCommands"
android:layout_marginTop="110dp"
android:text="Login" />
<ToggleButton
android:id="@+id/tbCHECK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/bLOGIN"
android:layout_alignBottom="@+id/bLOGIN"
android:layout_alignRight="@+id/etPASSWORD"
android:text="ToggleButton" />
</RelativeLayout>
and my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="com.example.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<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>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyArP83hWnigUMczcwT8J56TJtvOdcCSmRA"/>
<activity
android:name=".Maps"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Here are the codes for my app. Any help would be deeply appreciated.Thanks
No comments:
Post a Comment