应用程序意外停止请稍后再试 - 强制关闭 [英] The application stopped unexpectedly please try again later-Force close

查看:96
本文介绍了应用程序意外停止请稍后再试 - 强制关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在只是尝试创建一个使用eclipse登录的Android应用程序。但当我运行代码得到上面提到的错误。看着logcat它显示第36行的错误,但我不知道如何恢复它,



这是我的代码:



  package  com.example.login; 

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.os.Build;
import android.app.Activity;

public class MainActivity extends ActionBarActivity {
EditText un,pw;
TextView错误;
按钮确定;
/ * *首次创建活动时调用。 * /
@ Override
protected void onCreate(Bundle savedInstanceState){
super .onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pw =(EditText)findViewById(R.id.et_pw);
ok =(Button)findViewById(R.id.btn_login);
error =(TextView)findViewById(R.id.tv_error);

ok.setOnClickListener( new View.OnClickListener(){

@Override
public void onClick(查看v){
// TODO自动生成的方法存根

ArrayList< NameValuePair> postParameters = new ArrayList< NameValuePair>();
postParameters.add( new BasicNameValuePair( username,un.getText()。toString()));
postParameters.add( new BasicNameValuePair( password,pw .getText()。toString()));

String response = null;
尝试 {
response = CustomHttpClient.executeHttpPost( < target page url>,postParameters);
String res = response.toString();
res = res.replaceAll( \\\\ + );
if (res.equals( 1 ))
error.setText( 正确的用户名或密码) ;
else
error.setText( 抱歉!!用户名或密码不正确);
} catch (例外e){
un.setText(e.toString());
}

}
});
}
}



这里是我的logcat:

 04-04 11:14:26.657:E / AndroidRuntime(382):FATAL EXCEPTION:main 
04-04 11:14:26.657:E / AndroidRuntime(382):java.lang.RuntimeException:无法启动活动ComponentInfo {com .example.login / com.example.login.MainActivity}:java.lang.NullPointerException
04-04 11:14:26.657:E / AndroidRuntime(382):at android.app.ActivityThread.performLaunchActivity(ActivityThread。 java:1815)
04-04 11:14:26.657:E / AndroidRuntime(382):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
04-04 11:14: 26.657:E / AndroidRuntime(382):在android.app.ActivityThread.access $ 500(ActivityThread.java:122)
04-04 11:14:26.657:E / AndroidRuntime(382):在android.app。 ActivityThread $ H.handleMessage(ActivityThread.java:1024)
04-04 11:14:26.657:E / AndroidRuntime(382):at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 11:14:26.657:E / AndroidRuntime(382):at androi d.os.Looper.loop(Looper.java:132)
04-04 11:14:26.657:E / AndroidRuntime(382):在android.app.ActivityThread.main(ActivityThread.java:4123)
04-04 11:14:26.657:E / AndroidRuntime(382):at java.lang.reflect.Method.invokeNative(Native Method)
04-04 11:14:26.657:E / AndroidRuntime( 382):at java.lang.reflect.Method.invoke(Method.java:491)
04-04 11:14:26.657:E / AndroidRuntime(382):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:841)
04-04 11:14:26.657:E / AndroidRuntime(382):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-04 11:14:26.657:E / AndroidRuntime(382):at dalvik.system.NativeStart.main(Native Method)
04-04 11:14:26.657:E / AndroidRuntime(382) ):引起:java.lang.NullPointerException
04-04 11:14:26.657:E / AndroidRuntime(382):at com.example.login.MainActivity.onCreate(MainActivity.java:36)
04-04 11:14:26.657:E / AndroidRuntime(382):在android.app.Activity.performCreate(Activity.java:43) 97)
04-04 11:14:26.657:E / AndroidRuntime(382):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
04-04 11:14:26.657: E / AndroidRuntime(382):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
04-04 11:14:26.657:E / AndroidRuntime(382):... 11 more





如果我得到这个问题的解决方案,那就太明显了。



提前致谢。



修复代码块

解决方案

500(ActivityThread.java:122)
04-04 11:14:26.657:E / AndroidRuntime(382):at android .app.ActivityThread


H.handleMessage(ActivityThread.java:1024)
04-04 11:14:26.657:E / AndroidRuntime(382):at android.os。 Handler.dispatchMessage(Handler.java:99)
04-04 11:14:26.657:E / AndroidRuntime(382):at android.os.Looper.loop(Looper.java:132)
04 -04 11:14:26.657:E / AndroidRuntime(382):在android.app.ActivityThread.main(ActivityThread.java:4123)
04-04 11:14:26.657:E / AndroidRuntime(382): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 11:14:26.657:E / AndroidRuntime(382):at java.lang.reflect.Method.invoke(Method.java:491 )
04-04 11:14:26.657:E / AndroidRuntime(382):at com.android.internal.os.ZygoteInit


MethodAndArgsCaller.run(Zygo) teInit.java:841)
04-04 11:14:26.657:E / AndroidRuntime(382):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04 -04 11:14:26.657:E / AndroidRuntime(382):at dalvik.system.NativeStart.main(Native Method)
04-04 11:14:26.657:E / AndroidRuntime(382):引起: java.lang.NullPointerException
04-04 11:14:26.657:E / AndroidRuntime(382):at com.example.login.MainActivity.onCreate(MainActivity.java:36)
04-04 11 :14:26.657:E / AndroidRuntime(382):在android.app.Activity.performCreate(Activity.java:4397)
04-04 11:14:26.657:E / AndroidRuntime(382):在android。 app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
04-04 11:14:26.657:E / AndroidRuntime(382):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
04-04 11:14:26.657:E / AndroidRuntime(382):... 11更多





如果我得到它可以理解这个问题的解决方案。



提前致谢。



修复代码块 < /小>


Now just trying to create an android application to login using eclipse. But when i run the code getting the above mentioned error.Whil lookin at logcat it shows the error in line 36 but no idea for me to how to recover it,

here is my code:

package com.example.login;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.os.Build;
import android.app.Activity;

public class MainActivity extends ActionBarActivity {
    EditText un,pw;
    TextView error;
    Button ok;
    /** Called when the activity is first created. */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pw=(EditText)findViewById(R.id.et_pw);
        ok=(Button)findViewById(R.id.btn_login);
        error=(TextView)findViewById(R.id.tv_error);

        ok.setOnClickListener(new View.OnClickListener() {

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

                ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
                postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));

                String response = null;
                try {
                    response = CustomHttpClient.executeHttpPost("<target page url>", postParameters);
                    String res=response.toString();
                    res= res.replaceAll("\\s+","");
                    if(res.equals("1"))
                        error.setText("Correct Username or Password");
                    else
                        error.setText("Sorry!! Incorrect Username or Password");
                } catch (Exception e) {
                    un.setText(e.toString());
                }

            }
        });
    }
}


and here is my logcat:

04-04 11:14:26.657: E/AndroidRuntime(382): FATAL EXCEPTION: main
04-04 11:14:26.657: E/AndroidRuntime(382): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.login/com.example.login.MainActivity}: java.lang.NullPointerException
04-04 11:14:26.657: E/AndroidRuntime(382):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
04-04 11:14:26.657: E/AndroidRuntime(382):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
04-04 11:14:26.657: E/AndroidRuntime(382):  at android.app.ActivityThread.access$500(ActivityThread.java:122)
04-04 11:14:26.657: E/AndroidRuntime(382):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
04-04 11:14:26.657: E/AndroidRuntime(382):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 11:14:26.657: E/AndroidRuntime(382):  at android.os.Looper.loop(Looper.java:132)
04-04 11:14:26.657: E/AndroidRuntime(382):  at android.app.ActivityThread.main(ActivityThread.java:4123)
04-04 11:14:26.657: E/AndroidRuntime(382):  at java.lang.reflect.Method.invokeNative(Native Method)
04-04 11:14:26.657: E/AndroidRuntime(382):  at java.lang.reflect.Method.invoke(Method.java:491)
04-04 11:14:26.657: E/AndroidRuntime(382):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
04-04 11:14:26.657: E/AndroidRuntime(382):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-04 11:14:26.657: E/AndroidRuntime(382):  at dalvik.system.NativeStart.main(Native Method)
04-04 11:14:26.657: E/AndroidRuntime(382): Caused by: java.lang.NullPointerException
04-04 11:14:26.657: E/AndroidRuntime(382):  at com.example.login.MainActivity.onCreate(MainActivity.java:36)
04-04 11:14:26.657: E/AndroidRuntime(382):  at android.app.Activity.performCreate(Activity.java:4397)
04-04 11:14:26.657: E/AndroidRuntime(382):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
04-04 11:14:26.657: E/AndroidRuntime(382):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
04-04 11:14:26.657: E/AndroidRuntime(382):  ... 11 more



Its appreciable if i get an solution to this issue.

Thanks in advance.

code blocks fixed

解决方案

500(ActivityThread.java:122) 04-04 11:14:26.657: E/AndroidRuntime(382): at android.app.ActivityThread


H.handleMessage(ActivityThread.java:1024) 04-04 11:14:26.657: E/AndroidRuntime(382): at android.os.Handler.dispatchMessage(Handler.java:99) 04-04 11:14:26.657: E/AndroidRuntime(382): at android.os.Looper.loop(Looper.java:132) 04-04 11:14:26.657: E/AndroidRuntime(382): at android.app.ActivityThread.main(ActivityThread.java:4123) 04-04 11:14:26.657: E/AndroidRuntime(382): at java.lang.reflect.Method.invokeNative(Native Method) 04-04 11:14:26.657: E/AndroidRuntime(382): at java.lang.reflect.Method.invoke(Method.java:491) 04-04 11:14:26.657: E/AndroidRuntime(382): at com.android.internal.os.ZygoteInit


MethodAndArgsCaller.run(ZygoteInit.java:841) 04-04 11:14:26.657: E/AndroidRuntime(382): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 04-04 11:14:26.657: E/AndroidRuntime(382): at dalvik.system.NativeStart.main(Native Method) 04-04 11:14:26.657: E/AndroidRuntime(382): Caused by: java.lang.NullPointerException 04-04 11:14:26.657: E/AndroidRuntime(382): at com.example.login.MainActivity.onCreate(MainActivity.java:36) 04-04 11:14:26.657: E/AndroidRuntime(382): at android.app.Activity.performCreate(Activity.java:4397) 04-04 11:14:26.657: E/AndroidRuntime(382): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048) 04-04 11:14:26.657: E/AndroidRuntime(382): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779) 04-04 11:14:26.657: E/AndroidRuntime(382): ... 11 more



Its appreciable if i get an solution to this issue.

Thanks in advance.

code blocks fixed


这篇关于应用程序意外停止请稍后再试 - 强制关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆