显示java.lang.NullPointerException:通过的onclick引起 [英] onclick Caused by: java.lang.NullPointerException

查看:400
本文介绍了显示java.lang.NullPointerException:通过的onclick引起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid的发展。我最近encoutered一个问题时,我打我的应用程序的按钮。我不知道是什么原因导致这一点,因为它的工作完美我做了一些编辑与应用程序之前,加入另一项活动,闪屏,一些其他的东西上删除该软件菜单按钮。没有太多的它与这也正是这个问题存在的第一个活动做。我已经发布的所有code,但这个网站不肯让我这样做的。

I'm new to Android development. I recently encoutered an issue when I hit a button on my application. I'm not sure what caused this because it worked flawlessly before I did some editing with the app, adding another activity, removing the software menu buttons on the splash screen, some other stuff. Not much of it had to do with the first activity which is where this problem exists. I would've posted all of the code but this website refused to let me do so

当我打我的按钮(readybutton)我收到以下错误:

When I hit my button (readybutton) I get the following error:

  java.lang.RuntimeException: Unable to start activity        ComponentInfo 
  {com.unviewedchat/com.unviewedchat.SecondActivity}:
  java.lang.NullPointerException
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
  at android.app.ActivityThread.access$800(ActivityThread.java:135)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:136)
  at android.app.ActivityThread.main(ActivityThread.java:5017)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.NullPointerException
  at com.unviewedchat.SecondActivity.onCreate(SecondActivity.java:23)
  at android.app.Activity.performCreate(Activity.java:5231)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)

按钮code(readybutton)

Button code (readybutton)

button1 = (Button)findViewById(R.id.readybutton);
button1.setOnClickListener(this);

}
Button button1;

private void readyButtonclick()
{
 startActivity(new Intent("unviewedchat.SecondActivity"));
}

public void onClick(View v) {
    switch (v.getId()) {
        case R.id.readybutton:
            readyButtonclick();
            break;

    }

}

SecondActivity排22-23

    button2 = (Button)findViewById(R.id.help);
    button2.setOnClickListener(this); }

这code是软件菜单按钮打开帮助屏幕,这实际上影响按钮code为FirstActivity?

this code is for the software menu buttons to open the help screen, does this actually effect the button code for FirstActivity?

有上SecondActivity没有code,我试图访问,我试图去那个活动时有人点击该按钮。

There is no code on SecondActivity that i'm trying to access, i'm trying to go to that activity when someone hits the button.

我曾试图发布所有的错误报告,只有得到告诉它的格式不正确时,它是,无论哪种方式,我加得差不多了。

I attempted to post all of the error report, only to get told it wasn't formatted correctly when it was, either way I added almost all of it.

推荐答案

只要改变:

startActivity(new Intent("unviewedchat.SecondActivity"));

本:

startActivity(new Intent(this, SecondActivity.class));

这篇关于显示java.lang.NullPointerException:通过的onclick引起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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