Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 不幸的是,我的应用程序已经停止工作_Java_Android_Android Intent_Android Fragments - Fatal编程技术网

Java 不幸的是,我的应用程序已经停止工作

Java 不幸的是,我的应用程序已经停止工作,java,android,android-intent,android-fragments,Java,Android,Android Intent,Android Fragments,这是我的登录活动类,我想在登录后进行登录,但当我运行应用程序时,它显示不幸停止登录 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 andr

这是我的登录活动类,我想在登录后进行登录,但当我运行应用程序时,它显示不幸停止登录

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);
                }
            });
        }

}
loginsAccess.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>

<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>
以及您的登录成功活动

        Intent in = getIntent();
        if (in.getStringExtra("usr") != null) {
            final TextView setmsg = (TextView)findViewById(R.id.showmsg);
            setmsg.setText("Welcome \n "+in.getStringExtra("usr"));               
        }
这意味着您必须在清单文件中声明此部分

<uses-feature android:glEsVersion="0x00020000" android:required="true/>

您得到的是ClassCastException,您需要发布真实的stacktrace而不是图像,并告诉我们您得到错误的行。当我启动应用程序时,没有错误,当我在登录时放置凭据时,它显示您的应用程序不幸崩溃。发布两个活动的xml文件。首先,发布您的xml布局,然后清理项目并重新测试布局在哪里?你能发布你的第二个布局代码吗?@piyush谢谢它能工作logcat中有一个错误说google map android api V2只支持打开gls 2.o及以上的设备请告诉我这是什么好的必须确保你的应用程序运行的是google api你的目标SDK运行appkk是的我正在使用它运行应用程序google api和target sdk都是18,但您的项目运行正常吗?显示地图?@vaib还必须记住,您的模拟器支持谷歌API。
        Intent in = getIntent();
        if (in.getStringExtra("usr") != null) {
            final TextView setmsg = (TextView)findViewById(R.id.showmsg);
            setmsg.setText("Welcome \n "+in.getStringExtra("usr"));               
        }
<uses-feature android:glEsVersion="0x00020000" android:required="true/>