Here is my login activity class where i want to do login after login it show the map but when i run the app it show unfortunately stopped login
loginActivity.java
package com.ivb.login;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class LoginActivity extends Activity{
EditText edtemail,edtPassword;
Button btnLogin;
String strUsername,strPassword;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.login);
edtemail = (EditText)this.findViewById(R.id.edt_email);
edtPassword = (EditText)this.findViewById(R.id.edt_passwrd);
btnLogin = (Button)this.findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
strUsername = edtemail.getText().toString().trim();
strPassword = edtPassword.getText().toString().trim();
if(strUsername.equals("needin#gmail.com") && strPassword.equals("needin123"))
startActivity(new Intent(LoginActivity.this,LoginSuccess.class).putExtra("usr",(CharSequence)strUsername));
else
Toast.makeText(LoginActivity.this,"Invalid UserName or Password", Toast.LENGTH_LONG).show();
}
});
TextView registerScreen = (TextView) findViewById(R.id.link_to_register);
// Listening to register new account link
registerScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
startActivity(i);
}
});
}
}
loginsuccess.java
package com.ivb.login;
import javax.security.auth.PrivateCredentialPermission;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;
public class LoginSuccess extends Activity {
private GoogleMap googleMap;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.second);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
Intent in = getIntent();
if (in.getCharSequenceExtra("usr") != null) {
final TextView setmsg = (TextView)findViewById(R.id.showmsg);
setmsg.setText("Welcome \n "+in.getCharSequenceExtra("usr"));
}
}
private void initilizeMap() {
if (googleMap == null) {
googleMap =((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ivb.login"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.ivb.login.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<uses-permission android:name="com.ivb.login.permission.MAPS_RECEIVE"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<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="com.ivb.login.LoginActivity"
android:label="#string/app_name"
android:screenOrientation="sensor">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.ivb.login.RegisterActivity"
android:label="Register New Account"></activity>
<activity android:name="com.ivb.login.LoginSuccess"></activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyC-2jAJ7MEkho_gJv7KLeb-tHrU2zHDUQU" />
<uses-library android:name="com.google.android.maps"/>
</application>
</manifest>
second.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=".LoginSuccess" >
<LinearLayout android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#layout/header_gradient"
android:paddingTop="5dip"
android:paddingBottom="5dip" >
<ImageView android:src="#drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"/>
</LinearLayout>
<TextView
android:id="#+id/showmsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Welcome"
android:textSize="20dip" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TextView>
</RelativeLayout>
login.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff" >
<LinearLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#layout/header_gradient" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:orientation="vertical"
android:padding="10dip" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:src="#drawable/logo1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Email"
android:textColor="#372c24" />
<EditText
android:id="#+id/edt_email"
android:layout_width="209dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dip"
android:layout_marginTop="5dip"
android:ems="10"
android:hint="Enter Email Address"
android:inputType="textEmailAddress"
android:singleLine="true"
android:typeface="normal" >
<requestFocus />
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Password"
android:textColor="#372c24" />
<EditText
android:id="#+id/edt_passwrd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dip"
android:ems="10"
android:hint="Enter password"
android:inputType="textPassword"
android:password="true"
android:singleLine="true"
android:typeface="normal" />
<Button
android:id="#+id/btnLogin"
android:layout_width="133dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:layout_marginTop="10dip"
android:background="#acd28a"
android:clickable="true"
android:gravity="center"
android:paddingLeft="15dip"
android:text="Login" />
<TextView
android:id="#+id/link_to_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dip"
android:layout_marginTop="40dip"
android:gravity="center"
android:text="Need an account?sign up"
android:textColor="#0b84aa"
android:textSize="20dip" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
Change from
<TextView
android:id="#+id/showmsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Welcome"
android:textSize="20dip" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TextView>
to
<TextView
android:id="#+id/showmsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Welcome"
android:textSize="20dip" >
</TextView>
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
this is because your < /TextView> was closed after fragment class so you got this error.
Also change here
startActivity(new Intent(LoginActivity.this,LoginSuccess.class).putExtra("usr",strUsername));
and also in your LoginSuccess Activity
Intent in = getIntent();
if (in.getStringExtra("usr") != null) {
final TextView setmsg = (TextView)findViewById(R.id.showmsg);
setmsg.setText("Welcome \n "+in.getStringExtra("usr"));
}
That means you have to declare this part in your manifest file...
<uses-feature android:glEsVersion="0x00020000" android:required="true/>
and must use latest updated Google Play Service.
Related
i'm new at android studio and i'm developing my first app.
Everything worked fine until i implemented a splashscreen. Indeed, when i run the app, the splashcreen works, but then, it crashes.
The thing is that the splashscreen wasn't the first activity i've created (the main). I've created my app and when i finished it, i added a splashscreen.
Actually when i disable the splashscreen (the activity) and start directly with the previous "activity that appears on launch" (that is the "Menu"), it works fine.
And one weird thing: with the splashscreen enabled, it crashes only with certain devices. It runs perfectly with my Xiaomi Redmi Note 5 and a Galaxy S4 (or the nexus 5X emulator) but not with a Galaxy S3 and S6 .
I tried to replace the timer by a simple setonclicklistener button. But same, when it has to load the Menu, it crashes.
I haven't find similar problems on the forums so here i am !
The manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="#style/AppTheme">
<activity android:name=".Menu"/>
<activity android:name=".restaurant" />
<activity android:name=".courses" />
<activity android:name=".toilettes" />
<activity android:name=".distributeur" />
<activity android:name=".essence" />
<activity android:name=".hopital" />
<activity android:name=".Splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />
</application>
Here is the Splashscreen -java
package fr.libertyg.messervices;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Handler;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Timer;
public class Splashscreen extends AppCompatActivity {
private ImageView daccord;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_splashscreen);
final TextView random = (TextView) findViewById(R.id.random);
final String[] mesphrases = {"S1", "S2",
"S3", "S4", "S5","S6"};
int rando = (int) (Math.random() * 6);
random.setText(mesphrases[rando]);
this.daccord = findViewById(R.id.daccord);
daccord.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otheractivity = new Intent(Splashscreen.this, Menu.class);
startActivity(otheractivity);
finish();
}
});
}
The Splashscreen xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Splashscreen"
android:weightSum="10"
android:orientation="vertical"
android:background="#drawable/splashscreenfond">
<RelativeLayout
android:layout_weight="1.5"
android:layout_width="match_parent"
android:layout_height="0dp">
<TextView
android:id="#+id/spashscreenbienvenue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/splashscreenbienvenue"
android:textSize="40sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5">
<ImageView
android:id="#+id/logo"
android:layout_width="249dp"
android:layout_height="217dp"
android:layout_centerInParent="true"
android:src="#drawable/icon" />
<TextView
android:id="#+id/nom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/app_name"
android:textSize="30sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5">
<TextView
android:id="#+id/bonasavoir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="#string/bonasavoir"
android:textSize="17sp" />
<TextView
android:id="#+id/donnees"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/random"
android:layout_centerHorizontal="true"
android:text="#string/activezgps"
android:textSize="14sp" />
<TextView
android:id="#+id/random"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="13dp"
android:text="Un être humain a besoin d'environ 2000 kcal/jour"
android:textSize="14sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2">
<TextView
android:id="#+id/version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/version" />
<ImageView
android:id="#+id/daccord"
android:layout_width="124dp"
android:layout_height="105dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/daccord" />
</RelativeLayout>
</LinearLayout>
And the Menu -java
package fr.libertyg.messervices;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
public class Menu extends AppCompatActivity {
private ImageView distributeur;
private ImageView restaurant;
private ImageView courses;
private ImageView toilettes;
private ImageView essence;
private ImageView hopital;
AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_menu);
this.distributeur = findViewById(R.id.distributeur);
distributeur.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), distributeur.class);
startActivity(otherActivity);
}
});
this.restaurant = findViewById(R.id.restaurant);
restaurant.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), restaurant.class);
startActivity(otherActivity);
}
});
this.courses = findViewById(R.id.courses);
courses.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), courses.class);
startActivity(otherActivity);
}
});
this.toilettes = findViewById(R.id.toilettes);
toilettes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), toilettes.class);
startActivity(otherActivity);
}
});
this.essence = findViewById(R.id.essence);
essence.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), essence.class);
startActivity(otherActivity);
}
});
this.hopital = findViewById(R.id.hopital);
hopital.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), hopital.class);
startActivity(otherActivity);
}
});
MobileAds.initialize(this, "ca-app-pub-6520930039267956~4038950000");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
}
And the Menu xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#drawable/fond"
android:orientation="vertical"
android:weightSum="10">
<RelativeLayout
android:layout_weight="1.5"
android:layout_width="match_parent"
android:layout_height="0dp">
<TextView
android:id="#+id/bienvenue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/quoi"
android:textColor="#color/blanc"
android:textSize="30sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7.6">
<ImageView
android:id="#+id/distributeur"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_horizontal"
android:layout_marginStart="37dp"
android:layout_marginTop="29dp"
android:src="#drawable/distributeur" />
<ImageView
android:id="#+id/restaurant"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_horizontal"
android:layout_marginEnd="37dp"
android:layout_marginTop="29dp"
android:src="#drawable/restaurant" />
<ImageView
android:id="#+id/courses"
top="#+id/distributeur"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignStart="#+id/distributeur"
android:layout_centerVertical="true"
android:layout_gravity="center_horizontal"
android:src="#drawable/courses" />
<ImageView
android:id="#+id/toilettes"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignStart="#+id/restaurant"
android:layout_alignTop="#+id/courses"
android:layout_gravity="center_horizontal"
android:src="#drawable/toilettes" />
<ImageView
android:id="#+id/essence"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/distributeur"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="28dp"
android:src="#drawable/essence" />
<ImageView
android:id="#+id/hopital"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignStart="#+id/restaurant"
android:layout_alignTop="#+id/essence"
android:layout_gravity="center_horizontal"
android:src="#drawable/hopital" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-6520930039267956/3068657000" />
</RelativeLayout>
Thanks by advance for helping me.
In your app gradle make sure that libs use the same version, like:
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support:cardview-v7:28.0.0-alpha1'
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:gridlayout-v7:28.0.0-alpha1'
You probably don't need all of them.
Make the changes and then click "Sync Now"
Solved it:
I had to add this to the manifest:
android:largeHeap="true"
And it worked fine.
I have a button that sends the entered data to the database, After clicking on the button, an error appears unfortunately "project namе" has stopped, please, help!!!!
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kz.shoot.photo.photoshoot">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<!--uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" /-->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyMaterialTheme">
<activity
android:name=".LoginActivity"
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=".RegisterActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.RegisterActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package kz.shoot.photo.photoshoot;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener {
private static String TAG = MainActivity.class.getSimpleName();
private Toolbar mToolbar;
private FragmentDrawer drawerFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
drawerFragment.setDrawerListener(this);
// display the first navigation drawer view on app launch
displayView(0);
}
#Override
public void onDrawerItemSelected(View view, int position) {
displayView(position);
}
private void displayView(int position) {
Fragment fragment = null;
String title = getString(R.string.app_name);
switch (position) {
case 0:
fragment = new PhotoShootFragment();
title = getString(R.string.title_home);
break;
case 1:
fragment = new HistoryFragment();
title = getString(R.string.title_history);
break;
case 2:
fragment = new AboutFragment();
title = getString(R.string.title_about);
break;
case 3:
finish();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_body, fragment);
fragmentTransaction.commit();
// set the toolbar title
getSupportActionBar().setTitle(title);
}
}}
Fragment_Photoshoot.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:orientation="vertical"
tools:context="kz.shoot.photo.photoshoot.PhotoShootFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/label"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="30dp"
android:text="Мені? ?алам!"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:gravity="center_horizontal"
android:text="Жібергі?із келген жерді? суретін т?сірі?із!"
android:layout_below="#+id/label"
android:layout_alignParentStart="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/captured_photo"
android:contentDescription="#string/imageDesc"
android:theme="#android:style/Widget.ImageWell"
android:scrollIndicators="right"
android:layerType="hardware"
android:layout_centerVertical="false"
android:layout_centerInParent="false"
android:layout_alignWithParentIfMissing="false"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:minHeight="250dp"
android:maxHeight="300dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<Button
android:text="Камера"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cameraBtn"
android:layout_below="#+id/captured_photo"
android:onClick="takePicture"
android:layout_centerHorizontal="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_margin="10dp">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/mess_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/mess_title"
android:imeOptions="actionNone"
android:inputType="text"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Хабарлама категориясын та?да?ыз"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Spinner
android:id="#+id/category_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_margin="10dp"
android:layout_marginTop="0dp">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/message"
android:layout_marginTop="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/photo_description"
android:inputType="text|textMultiLine"
android:maxLines="25"
android:elevation="0dp"
android:minHeight="82dp"
android:scrollbars="vertical"
android:scrollbarStyle="insideOverlay" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<Button
android:text="Жіберу"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/sendBtn"
android:layout_below="#+id/captured_photo"
android:layout_centerHorizontal="true" />
</LinearLayout>
</android.support.v7.widget.LinearLayoutCompat>
</LinearLayout>
</ScrollView>
</LinearLayout>
I am using eclipse for developing a game for android. The game is pretty much finished but it won't launch correctly on my emulator of choice (BlueStacks).
It only shows a white screen and the infobar for about 0.5 seconds before crashing. App is still open in background after crashing but can't do or display anything.
I can compile and install the application and the syntax is correct... I assume that my mistake is somewhere in the manifest.
here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.ralfkraemer.starsandstrikes"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="de.ralfkraemer.starsandstrikes.MainMenu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The following is my main activity class
package de.ralfkraemer.starsandstrikes;
import java.io.IOException;
import java.util.Random;
import de.ralfkraemer.starsandstrikes.R;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainMenu extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitymainmenu);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getActionBar();
actionBar.hide();
randomizeFact();
}
// RANDOM FACT
String[] factresource = getResources().getStringArray(R.array.factres);
protected void randomizeFact(){
TextView randomFact = (TextView)findViewById(R.id.text1);
Random random = new Random();
int maxIndex = factresource.length;
int generatedIndex = random.nextInt(maxIndex);
randomFact.setText(factresource[generatedIndex]);
}
// START GAME
public void startGame(){
Game currentGame = new Game();
currentGame.setScore(0);
setContentView(R.layout.activitygame);
currentGame.running = true;
}
// PLAY STORE (RATE)
public void openPlayStore(){
Uri uri = Uri.parse("url");
Intent intent = new Intent (Intent.ACTION_VIEW, uri);
startActivity(intent);
}
public void goToAbout(){
setContentView(R.layout.activityabout);
}
public void goToHowToPlay(){
setContentView(R.layout.activityhowtoplay);
}
public void goToHighscores() throws IOException{
Highscores highscores = new Highscores();
setContentView(R.layout.activityhighscores);
}
}
And here is the main activity xml
<LinearLayout 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:orientation="vertical"
android:background="#drawable/background"
tools:context="${linearPackage}.${activityClass}" >
<ImageView
android:id="#+id/header"
android:contentDescription="#string/header_content"
android:src="#drawable/logo_mainmenu"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="10dp" />
<Button
android:id="#+id/button_play"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="65dp"
android:layout_marginRight="65dp"
android:text="#string/mm_button_play"
android:textSize="22sp"
android:onClick="startGame"
android:background="#drawable/button_default" />
<TextView
android:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:text="#string/mm_randomfact_placeholder"
android:textSize="16sp"
android:gravity="center"/>
<Button
android:id="#+id/button_randomfact"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="65dp"
android:layout_marginRight="65dp"
android:text="#string/mm_button_randomfact"
android:textSize="18sp"
android:onClick="randomizeFact"
android:background="#drawable/button_default" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:orientation="vertical"
android:baselineAligned="false" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:layout_weight="1" >
<Button
android:id="#+id/button_highscores"
android:layout_width="0dip"
android:layout_height="55dp"
android:layout_weight="1"
tools:ignore="NestedWeights"
android:text="#string/mm_button_highscores"
style="android:attr/buttonBarButtonStyle"
android:background="#drawable/button_default"
android:onClick="goToHighscores" />
<Button
android:id="#+id/button_howtoplay"
android:layout_width="0dip"
android:layout_height="55dp"
android:layout_weight="1"
tools:ignore="NestedWeights"
android:text="#string/mm_button_howtoplay"
style="android:attr/buttonBarButtonStyle"
android:background="#drawable/button_default"
android:onClick="goToHowToPlay" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:layout_weight="1" >
<Button
android:id="#+id/button_about"
android:layout_width="0dip"
android:layout_height="55dp"
android:layout_weight="1"
tools:ignore="NestedWeights"
android:text="#string/mm_button_about"
style="android:attr/buttonBarButtonStyle"
android:background="#drawable/button_default"
android:onClick="goToAbout" />
<Button
android:id="#+id/button_rate"
android:layout_width="0dip"
android:layout_height="55dp"
android:layout_weight="1"
tools:ignore="NestedWeights"
android:text="#string/mm_button_rate"
style="android:attr/buttonBarButtonStyle"
android:background="#drawable/button_default"
android:onClick="openPlayStore" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
You are calling getResources while the activity is instantiating on this line here:
// RANDOM FACT
String[] factresource = getResources().getStringArray(R.array.factres);
and the implied Activity.this object does not have a valid context, so it crashes. You need to call this in onCreate or in another method that is called after the object instantiates.
I am writing an app that will eventually use Bluetooth to get a value for two devices' proximity to one another. I am currently trying to use buttons and onClick/onclicklistener etc to bring switch screens from the main UI to a log in or sign up page. Now my app is forcing close on start up and I'm not sure why. Thanks for any help!!
MainActivity:
package com.example.chirp;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter() ;
String status; {
if (bluetooth != null)
{
if (bluetooth.isEnabled())
{
String mydeviceaddress = bluetooth.getAddress();
String mydevicename = bluetooth.getName();
status = mydevicename + ":" + mydeviceaddress;
}
else
{
status = "Bluetooth is not Enabled.";
}
}
Toast.makeText(this, status, Toast.LENGTH_LONG).show();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button loginbutton = (Button) findViewById(R.id.button1);
loginbutton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
setContentView(R.layout.loginscreen);
}
});
}
#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;
}
public void newMessage(View v){
Intent intent = new Intent(this,loginscreen.class);
startActivity(intent);
}
}
activity_main.xml
<LinearLayout 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:orientation="vertical"
android:background="#7FFFD4"
android:padding="20dp"
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=".MainActivity" >
<!-- <public void loginhere(View view) {
android:
}/>-->
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:text="#string/hello_world"
android:textSize="50sp"
android:typeface="serif" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_marginTop="100dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="32sp"
android:layout_gravity="center_horizontal"
android:text="Slide to Quick Find"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="#+id/button2"
android:layout_width="396dp"
android:layout_height="100dp"
android:layout_marginLeft="75dp"
android:layout_marginTop="300dp"
android:textSize="50sp"
android:text="Sign Up" />
<Button
android:id="#+id/button1"
android:layout_width="396dp"
android:layout_height="100dp"
android:layout_marginLeft="75dp"
android:layout_marginTop="50dp"
android:textSize="50sp"
android:onClick="onclick"
android:text="Log In" />
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chirp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"
android:requiresSmallestWidthDp="320"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.chirp.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="com.example.chirp.loginscreen"
android:label="CHIRP"
/>
</application>
</manifest>
loginscreen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:background="#7FFFD4"
android:padding="20dp"
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=".login" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remember Username" />
/
</LinearLayout>
Move this code inside your onCreate method:
if (bluetooth != null) {
if (bluetooth.isEnabled()) {
String mydeviceaddress = bluetooth.getAddress();
String mydevicename = bluetooth.getName();
status = mydevicename + ":" + mydeviceaddress;
} else {
status = "Bluetooth is not Enabled.";
}
//etc...
Currently this code block is outside of any method of your activity and that is for sure not what you want to have.
I have tried editing the code as it would re-install the application on the emulator but again I'm getting the same error again and again.
It's saying edit source lookup path and showing a button for it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/images"
android:orientation="vertical" >
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter the text here"
android:textColor="#000000"
android:textSize="30dp" />
<EditText
android:id="#+id/textReader"
android:layout_width="match_parent"
android:layout_height="150dp"
android:inputType="textMultiLine"
/>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/startReading"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Start reading"
android:textSize="15dp" />
<Button
android:id="#+id/clearBox"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Clear Box"
android:textSize="15dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7.58" >
</RelativeLayout>
</LinearLayout>
<EditText
android:id="#+id/textDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
That was the main.xml file above.
package a.fr.read;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class FastreaderActivity extends Activity {
/** Called when the activity is first created. */
Button startReading,clearBox;
EditText textReader;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startReading=(Button)findViewById(R.id.textReader);
clearBox=(Button)findViewById(R.id.textReader);
textReader=(EditText) findViewById(R.id.textReader);
clearBox.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
textReader.setText("");
}
});
startReading.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
}
And this is the java code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="a.fr.read"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<activity
android:name=".FastreaderActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And that was Android manifest file.
First clean your project and refresh that project(In Eclipse- Project-clean)for refresh(go that projectName(ListVeiwdemo) and right click and refresh option will come.)