ndroid-新人求助 java.lang.NullPointerException

问题描述

新人求助 java.lang.NullPointerException

04-26 21:42:40.039: E/AndroidRuntime(1125): FATAL EXCEPTION: main
04-26 21:42:40.039: E/AndroidRuntime(1125): Process: com.example.remotecontrol, PID: 1125
04-26 21:42:40.039: E/AndroidRuntime(1125): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.remotecontrol/com.example.remotecontrol.RemoteControlActivity}: java.lang.NullPointerException
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.app.ActivityThread.access$700(ActivityThread.java:135)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.os.Handler.dispatchMessage(Handler.java:102)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.os.Looper.loop(Looper.java:137)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.app.ActivityThread.main(ActivityThread.java:4998)
04-26 21:42:40.039: E/AndroidRuntime(1125): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 21:42:40.039: E/AndroidRuntime(1125): at java.lang.reflect.Method.invoke(Method.java:515)
04-26 21:42:40.039: E/AndroidRuntime(1125): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
04-26 21:42:40.039: E/AndroidRuntime(1125): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
04-26 21:42:40.039: E/AndroidRuntime(1125): at dalvik.system.NativeStart.main(Native Method)
04-26 21:42:40.039: E/AndroidRuntime(1125): Caused by: java.lang.NullPointerException
04-26 21:42:40.039: E/AndroidRuntime(1125): at com.example.remotecontrol.RemoteControlFragment.onCreateView(RemoteControlFragment.java:43)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.app.Activity.performStart(Activity.java:5253)
04-26 21:42:40.039: E/AndroidRuntime(1125): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2149)
04-26 21:42:40.039: E/AndroidRuntime(1125): ... 11 more

解决方案

。。。。。。我知道了= = 我傻逼吧 i 打成 1 了

解决方案二:

这是第43行: for(int j = 0; j < row.getChildCount(); j++){

解决方案三:

我晕,这是空指针异常,不贴出代码,别人怎么找错误 !

解决方案四:

 04-26 21:42:40.039: E/AndroidRuntime(1125): Caused by: java.lang.NullPointerException
04-26 21:42:40.039: E/AndroidRuntime(1125): at com.example.remotecontrol.RemoteControlFragment.onCreateView(RemoteControlFragment.java:43)

解决方案五:

代码:

RemoteControlFragment:

package com.example.remotecontrol;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class RemoteControlFragment extends Fragment {
private TextView mSelectedTextView;
private TextView mWorkingTextView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View v = inflater.inflate(R.layout.fragment_remote_control, container,false);
    mSelectedTextView = (TextView)v.findViewById(R.id.fragment_remote_control_selectedtextView);
    mWorkingTextView = (TextView)v.findViewById(R.id.fragment_remote_control_workingTextView);
    View.OnClickListener numberButtonListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            TextView textView = (TextView)v;
            String working = mWorkingTextView.getText().toString();
            String text = textView.getText().toString();
            if(working.equals("0")){
                mWorkingTextView.setText(text);
            } else{
                mWorkingTextView.setText(working + text);
            }
        }
    };
    TableLayout tableLayout = (TableLayout)v.findViewById(R.id.fragment_remote_control_tableLayout);
    int number = 1;
    for(int i = 2; 1 < tableLayout.getChildCount() - 1; i++){
        TableRow row = (TableRow)tableLayout.getChildAt(i);
        for(int j = 0; j < row.getChildCount(); j++){
            Button button = (Button)row.getChildAt(j);
            button.setText("" + number);
            button.setOnClickListener(numberButtonListener);
            number++;
        }
    }

    TableRow bottomRow = (TableRow)tableLayout.getChildAt(tableLayout.getChildCount() - 1);
    Button deleteButton = (Button)bottomRow.getChildAt(0);
    deleteButton.setText("Delete");
    deleteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mWorkingTextView.setText("0");

        }
    });

    Button zeroButton = (Button)bottomRow.getChildAt(1);
    zeroButton.setText("0");
    zeroButton.setOnClickListener(numberButtonListener);

    Button enterButton =(Button)bottomRow.getChildAt(2);
    enterButton.setText("Enter");
    enterButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            CharSequence working = mWorkingTextView.getText();
            if(working.length() > 0){
                mSelectedTextView.setText(working);
                mWorkingTextView.setText("0");
            }

        }
    });
    return v;
}

}

解决方案六:

RemoteControlFragment.java 第43行有一个对象没赋值就用了

解决方案七:

43行是哪句 你粘出来

时间: 2025-01-08 10:23:56

ndroid-新人求助 java.lang.NullPointerException的相关文章

求助java.lang.NullPointerException

问题描述 我一直不能运行,我不懂应该怎样改,我很苦恼啊只一直弹出Exceptioninthread"main"java.lang.NullPointerExceptionatLine.<init>(Te​​stLine.java:29)atTestLine.main(TestLine.java:230)谁可以帮帮忙,麻烦各位了.../***@(#)Test.java***@author*@version1.002011/3/30*/classLine{protectedSt

配置文件-大神求助《properties.load(fileInputStream )》java.lang.NullPointerException

问题描述 大神求助<properties.load(fileInputStream )>java.lang.NullPointerException 我明明把配置文件路径给对了,可是总是说空指针异常.查了一下午还没有弄明白.求大神解救...调试总是显示在 properties.load(fileInputStream );出现异常..代码如下: public Configuration () throws FileNotFoundException { try { File file=new

android-在fragment转换中出现java.lang.NullPointerException

问题描述 在fragment转换中出现java.lang.NullPointerException 最近学校让做个android音乐播放器,我跟着论坛的教学做到这里时会出现闪退的问题,不知道怎么解决,求助(我是小白,如果可以请说详细些,谢谢啦) 解决方案 http://bbs.csdn.net/topics/390509766 解决方案二: 这是出错的代码 package com.example.test_01; import android.app.Fragment;import androi

JsonMappingException: (was java.lang.NullPointerException)

使用jackson 序列化Java对象的时候报异常: Java代码   com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.chanjet.gov.Student["age"])       at com.fasterxml.jackson.databind.JsonMappingException.

java.lang.NullPointerException: Expected timestamp

java.lang.NullPointerException: Expected timestamp in the Flume event headers, but it was null java.lang.NullPointerException: Expected timestamp in the Flume event headers, but it was null 使用flume的时候出现的问题. sink是hdfs,然后使用目录自动生成功能.出现如题的错误,看官网文档说的是需要在每

JSP页面中出现的一个异常:org.apache.jasper.JasperException: java.lang.NullPointerException

先把出现的异常情况贴出来吧: type Exception report messagejava.lang.NullPointerException descriptionThe server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: java.lang.NullPointerException

图片-svn更新后,jsp页面报java.lang.NullPointerException

问题描述 svn更新后,jsp页面报java.lang.NullPointerException 请大神指点 谢谢 解决方案 svn一般要先更新再提交,有报错的话就先修改错误 解决方案二: 空指针异常,看看你同组的人有没有修改过东西,没有全部上传

java web java.lang.NullPointerException

问题描述 java web java.lang.NullPointerException 严重: Servlet.service() for servlet [selectServlet] in context with path [/Exercise] threw exceptionjava.lang.NullPointerException at DB.DataBaseConnection.selectOperation1(DataBaseConnection.java:45) at Ser

异常-java.lang.NullPointerException

问题描述 java.lang.NullPointerException 请问下这种异常怎么解决呢 解决方案 空指针错误.这种错误一般是由于: 1.使用的类对象为null 2.指针越界 3.配置文件配置路径有错,无法找到路径 解决方案二: SDK和ADT为22.6.2版本 工程为4.4.2 新建了一个工程 ,代码编写好后并没有报错,在安装支持后报出如下错误: java.lang.RuntimeException: Unable to start activity ComponentInfo{com