Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.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 android.view.view android.view.view.findViewById(int)和#x27;关于空对象引用_Java_Android_Nullpointerexception - Fatal编程技术网

Java android.view.view android.view.view.findViewById(int)和#x27;关于空对象引用

Java android.view.view android.view.view.findViewById(int)和#x27;关于空对象引用,java,android,nullpointerexception,Java,Android,Nullpointerexception,我有个问题。当我编译时,总是会出现如下错误。所以我希望有人能帮助理解这个问题。当我打开活动时,总是堆叠。。。请帮帮我 SettingAct.JAVA package com.solusiwebmaster.antrian; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import an

我有个问题。当我编译时,总是会出现如下错误。所以我希望有人能帮助理解这个问题。当我打开活动时,总是堆叠。。。请帮帮我

SettingAct.JAVA

package com.solusiwebmaster.antrian;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.Toast;
import com.solusiwebmaster.antrian.SettingAct_ViewHelper.SettingActViewInterface;
import tools.AntrianConfig;
import tools.AntrianHelper;
import tools.AntrianHelper.AntrianChanged;

public class SettingAct extends Activity {
    AntrianHelper antrianHelper;
    AntrianConfig antrianconfig;
    EditText et_antrian;
    EditText et_loket;
    LayoutInflater inflater;
    private Boolean settingchanged = Boolean.valueOf(false);
    SettingActViewInterface settingviewInterface = new C06411();
    SharedPreferences sharedpref;
    TableLayout table;
    SettingAct_ViewHelper viewhelpersetting;


    class C06411 implements SettingActViewInterface {
        C06411() {
        }

        public void setServerPort(int port) {
            if (SettingAct.this.antrianconfig.port != port && (port+"").length() >= 4) {
                SettingAct.this.antrianconfig.port = port;
                SettingAct.this.settingchanged = Boolean.valueOf(true);
            }
        }

        public void setServerAddress(String s) {
            if (!SettingAct.this.antrianconfig.serverAddress.equals(s)) {
                SettingAct.this.antrianconfig.serverAddress = s;
                SettingAct.this.settingchanged = Boolean.valueOf(true);
            }
        }

        public void setPlaySoundAt(int i) {
            SettingAct.this.antrianconfig.playSoundAt = i;
            SettingAct.this.settingchanged = Boolean.valueOf(true);
        }

        public void setLoket(int loket) {
            if (SettingAct.this.antrianconfig.loket != loket) {
                SettingAct.this.antrianconfig.loket = loket;
                SettingAct.this.settingchanged = Boolean.valueOf(true);
            }
        }

        public void setAppMode(int i) {
            System.out.println("apasih appmodenya : " + i + "servernya " + AntrianConfig.M_SERVER);
            SettingAct.this.antrianconfig.appMode = i;
            SettingAct.this.settingchanged = Boolean.valueOf(true);
            SettingAct.this.viewhelpersetting.addAllsettingChild();
        }

        public void setAntrian(int _antrian) {
            SettingAct.this.antrianHelper.setAntrian(_antrian);
            SettingAct.this.settingchanged = Boolean.valueOf(true);
        }

        public int getServerPort() {
            return SettingAct.this.antrianconfig.port;
        }

        public String getServerAddress() {
            String add = SettingAct.this.antrianconfig.serverAddress;
            if (add == null) {
                return "";
            }
            return add;
        }

        public int getPlaysoundAt() {
            return SettingAct.this.antrianconfig.playSoundAt;
        }

        public int getLoket() {
            return SettingAct.this.antrianconfig.loket;
        }

        public int getCurrentAntrian() {
            return SettingAct.this.antrianHelper.getAntrian();
        }

        public int getAppMode() {
            return SettingAct.this.antrianconfig.appMode;
        }
    }

    class C06422 implements AntrianChanged {
        C06422() {
        }

        public void warning(String msg) {
            Toast.makeText(SettingAct.this, msg, 0).show();
        }

        public void antrianChanged() {
            if (SettingAct.this.et_antrian != null) {
                SettingAct.this.et_antrian.setText(new StringBuilder(String.valueOf(SettingAct.this.antrianHelper.getAntrian())).toString());
            }
            if (SettingAct.this.et_loket != null) {
                SettingAct.this.et_loket.setText(new StringBuilder(String.valueOf(SettingAct.this.antrianHelper.antrianConfig.loket)).toString());
            }
        }
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        this.table = (TableLayout) findViewById(C0419R.id.as_table);
        this.inflater = getLayoutInflater();
        this.sharedpref = getSharedPreferences(AntrianConfig.SHARED_PREFFILE, 0);
        this.antrianconfig = new AntrianConfig(this.sharedpref);
        this.antrianHelper = new AntrianHelper(this, this.sharedpref);
        this.antrianHelper.setAntrianChangedCallback(new C06422());
        this.antrianHelper.loadCurrentAntrian();
        this.viewhelpersetting = new SettingAct_ViewHelper(this, this.settingviewInterface);
        this.viewhelpersetting.addAllsettingChild();
    }

    protected void onDestroy() {
        if (this.settingchanged.booleanValue()) {
            this.antrianconfig.saveConfig();
            try {
                ActBroadcastReceiver.sendSettingChanged(this);
            } catch (Exception e) {
            }
        }
        super.onDestroy();
    }

    public static void goHere(Activity actIn) {
        actIn.startActivity(new Intent(actIn, SettingAct.class));
    }
}
SettingAct_ViewHelper.java

    package com.solusiwebmaster.antrian;

import android.app.Activity;
import android.graphics.Color;
import android.support.v4.view.ViewCompat;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;

import server.AntrianResponse;
import server.ParamRequest;
import tools.AntrianConfig;
import tools.MyClient;
import tools.MyClient.MyClientCallback;
import tools.NetWorkTools;
import tools.ResourceTools;
import uihelper.SmallTombolBulat;
import uihelper.TombolSwitch;

public class SettingAct_ViewHelper {
    Activity act;
    EditText et_antrian;
    EditText et_loket;
    SettingActViewInterface ifc;
    MyClient oldclient;

    LayoutInflater inflater = this.act.getLayoutInflater();
    TableLayout table = ((TableLayout) this.act.findViewById(R.id.as_table));

    TombolSwitch tombolstatus;
    public SettingAct activity;


    class C04201 implements OnKeyListener {
        C04201() {
        }

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == 1) {
                try {
                    SettingAct_ViewHelper.this.ifc.setLoket(Integer.parseInt(((EditText) v).getText().toString()));
                } catch (Exception e) {
                }
            }
            return false;
        }
    }

    class C04212 implements OnKeyListener {
        C04212() {
        }

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == 1) {
                try {
                    SettingAct_ViewHelper.this.ifc.setAntrian(Integer.parseInt(((EditText) v).getText().toString()));
                } catch (Exception e) {
                }
            }
            return false;
        }
    }

    class C04223 implements OnItemSelectedListener {
        C04223() {
        }

        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
            if (position != SettingAct_ViewHelper.this.ifc.getAppMode()) {
                SettingAct_ViewHelper.this.ifc.setAppMode(position);
            }
        }

        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    }

    class C04234 implements OnKeyListener {
        C04234() {
        }

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            try {
                if (event.getAction() == 1) {
                    EditText et = (EditText) v;
                    String text = et.getText().toString();
                    if (!text.startsWith("http://")) {
                        text = "http://" + text;
                        et.setText(text);
                        et.setSelection(text.length());
                    }
                    SettingAct_ViewHelper.this.ifc.setServerAddress(text);
                }
            } catch (Exception e) {
            }
            return false;
        }
    }

    class C04245 implements OnItemSelectedListener {
        C04245() {
        }

        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
            int psoundat = position == 0 ? AntrianConfig.M_CLIENT : AntrianConfig.M_SERVER;
            if (psoundat != SettingAct_ViewHelper.this.ifc.getPlaysoundAt()) {
                SettingAct_ViewHelper.this.ifc.setPlaySoundAt(psoundat);
                SettingAct_ViewHelper.this.addAllsettingChild();
            }
        }

        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    }

    class C04256 implements OnKeyListener {
        C04256() {
        }

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            try {
                if (event.getAction() == 1) {
                    EditText et = (EditText) v;
                    if (et.getText().toString().length() >= 4) {
                        SettingAct_ViewHelper.this.ifc.setServerPort(Integer.parseInt(et.getText().toString()));
                    }
                }
            } catch (Exception e) {
            }
            return false;
        }
    }

    class C04267 implements OnClickListener {
        C04267() {
        }

        public void onClick(View v) {
            Toast.makeText(SettingAct_ViewHelper.this.act, "Tutup dan buka aplikasi untuk menyalakan server", 0).show();
        }
    }

    public interface SettingActViewInterface {
        int getAppMode();

        int getCurrentAntrian();

        int getLoket();

        int getPlaysoundAt();

        String getServerAddress();

        int getServerPort();

        void setAntrian(int i);

        void setAppMode(int i);

        void setLoket(int i);

        void setPlaySoundAt(int i);

        void setServerAddress(String str);

        void setServerPort(int i);
    }

    class C06438 implements MyClientCallback {
        C06438() {
        }

        public void result(int i) {
            if (i == 200) {
                SettingAct_ViewHelper.this.tombolstatus.setOn(Boolean.valueOf(true));
            } else {
                SettingAct_ViewHelper.this.tombolstatus.setOn(Boolean.valueOf(false));
            }
        }

        public void error(String msg) {
        }
    }

    public SettingAct_ViewHelper(Activity actIn, SettingActViewInterface ifcIn) {
        this.act = actIn;
        this.ifc = ifcIn;
        ((TextView) this.act.findViewById(R.id.as_title)).setText(new StringBuilder(String.valueOf(this.act.getResources().getString(R.string.app_name))).append(" v").append(ResourceTools.getVersionname(this.act)).toString());
    }

    public void addAllsettingChild() {
        this.table.removeAllViews();
        addSettingChild();
        addClientMenu();
        addServerMenu();
    }

    class ChildView {
        public View rootview=SettingAct_ViewHelper.this.inflater.inflate(R.layout.activity_setting_child, SettingAct_ViewHelper.this.table, false);
        public LinearLayout childlinear = ((LinearLayout) this.rootview.findViewById(R.id.asc_childLinear));
        public TextView textview = ((TextView) this.rootview.findViewById(R.id.asc_text));
        public SmallTombolBulat tombol = ((SmallTombolBulat) this.rootview.findViewById(R.id.asc_tombol));

        public ChildView(int iconcode, String textlabel, int circleColor) {
            this.rootview = SettingAct_ViewHelper.this.inflater.inflate(R.layout.activity_setting_child, SettingAct_ViewHelper.this.table, false);
            try {
                this.tombol.setIconCode(SettingAct_ViewHelper.this.act.getResources().getString(iconcode));
            } catch (Exception e) {
            }
            this.textview.setText(textlabel);
            this.tombol.setCircleColor(circleColor);
        }
    }

    private void addSettingChild() {
        addEditextChild(R.string.im_laptop, "Loket", this.ifc.getLoket()+"", Color.parseColor("#e63e6f"), new C04201());
        addEditextChild(R.string.im_user, "Antrian", this.ifc.getCurrentAntrian()+"", Color.parseColor("#730679"), new C04212());
        ChildView modechild = new ChildView(R.string.im_tree, "Mode", Color.parseColor("#99c210"));
        String[] modeopt = new String[]{"Standalone", "Client", "Server"};
        Spinner spinner = new Spinner(this.act);
        spinner.setAdapter(new ArrayAdapter(this.act, 17367048, modeopt));
        spinner.setSelection(this.ifc.getAppMode());
        spinner.setOnItemSelectedListener(new C04223());
        modechild.childlinear.addView(spinner);
        this.table.addView(modechild.rootview);
    }

    private void addClientMenu() {
        int psound = 0;
        if (this.ifc.getAppMode() == AntrianConfig.M_CLIENT) {
            String serveradd = this.ifc.getServerAddress();
            if (serveradd == null) {
                serveradd = "";
            }
            addEditextChild(R.string.im_podcast, "Server", serveradd, Color.parseColor("#ffab31"), 1, new C04234());
            ChildView modechild = new ChildView(R.string.im_megaphone, "Speakers", Color.parseColor("#99c210"));
            String[] modeopt = new String[]{"Client", "Server"};
            Spinner spinner = new Spinner(this.act);
            spinner.setAdapter(new ArrayAdapter(this.act, 17367048, modeopt));
            if (this.ifc.getPlaysoundAt() != 1) {
                psound = 1;
            }
            spinner.setSelection(psound);
            spinner.setOnItemSelectedListener(new C04245());
            modechild.childlinear.addView(spinner);
            this.table.addView(modechild.rootview);
        }
    }

    private void addServerMenu() {
        if (Integer.valueOf(this.ifc.getAppMode()).equals(Integer.valueOf(AntrianConfig.M_SERVER))) {
            addEditextChild(R.string.im_podcast, "Port", new StringBuilder(String.valueOf(this.ifc.getServerPort())).toString(), Color.parseColor("#730679"), new C04256());
            String devip = NetWorkTools.getIpAddress(this.act);
            if (devip == null) {
                devip = "";
            }
            devip = "http://" + devip + ":" + this.ifc.getServerPort() + "/";
            ChildView ipcv = new ChildView(R.string.im_podcast, "Server URL", Color.parseColor("#99c210"));
            TextView tv = new TextView(this.act);
            tv.setTextSize(2, 16.0f);
            tv.setTextColor(ViewCompat.MEASURED_STATE_MASK);
            tv.setGravity(16);
            tv.setText(devip);
            ipcv.childlinear.addView(tv);
            this.table.addView(ipcv.rootview);
            ChildView cv = new ChildView(R.string.im_podcast, "Server Status", Color.parseColor("#99c210"));
            this.tombolstatus = new TombolSwitch(this.act);
            this.tombolstatus.setOn(Boolean.valueOf(false));
            cv.childlinear.addView(this.tombolstatus);
            this.table.addView(cv.rootview);
            this.tombolstatus.setOnClickListener(new C04267());
            getStatusServer();
        }
    }

    private void addEditextChild(int icon, String textlabel, String valtext, int circleColor, OnKeyListener keylistener) {
        addEditextChild(icon, textlabel, valtext, circleColor, 2, keylistener);
    }

    private void addEditextChild(int icon, String textlabel, String valtext, int circleColor, int editortype, OnKeyListener keylistener) {
        ChildView cvLoket = new ChildView(icon, textlabel, circleColor);
        EditText loketeditext = new EditText(this.act);
        loketeditext.setText(valtext);
        loketeditext.setInputType(editortype);
        loketeditext.setOnKeyListener(keylistener);
        cvLoket.childlinear.addView(loketeditext);
        if (textlabel.equals("Loket")) {
            this.et_loket = loketeditext;
        }
        if (textlabel.equals("Antrian")) {
            this.et_antrian = loketeditext;
        }
        this.table.addView(cvLoket.rootview);
    }

    private void getStatusServer() {
        try {
            this.oldclient.disconnect();
        } catch (Exception e) {
        }
        if (this.tombolstatus != null) {
            ParamRequest param = new ParamRequest();
            param.allowresponse = Boolean.valueOf(true);
            param.reqmode = AntrianResponse.REQMODE_TEST;
            this.oldclient = MyClient.getAntrian(this.act, new C06438(), "http://127.0.0.1:" + this.ifc.getServerPort(), param);
        }
    }
}
package com.solusiwebmaster.antrian;
导入android.app.Activity;
导入android.graphics.Color;
导入android.support.v4.view.ViewCompat;
导入android.view.KeyEvent;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.view.view.OnKeyListener;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemSelectedListener;
导入android.widget.ArrayAdapter;
导入android.widget.EditText;
导入android.widget.LinearLayout;
导入android.widget.Spinner;
导入android.widget.TableLayout;
导入android.widget.TextView;
导入android.widget.Toast;
导入服务器响应;
导入server.ParamRequest;
导入tools.AntrianConfig;
导入tools.MyClient;
导入tools.MyClient.MyClientCallback;
导入工具。网络工具;
导入工具。资源工具;
导入uihelper.SmallTombolBulat;
导入uihelper.TombolSwitch;

公共类设置Act_ViewHelper{ 活动法; 编辑文本et_antrian; 编辑文本et_loket; 设置ActViewInterface ifc; 我的客户老客户; LayoutInflater充气器=this.act.getLayoutInflater(); TableLayout table=((TableLayout)this.act.findviewbyd(R.id.as_table)); TombolSwitch tombolstatus; 公共设置行为活动; 类C04201实现OnKeyListener{ C04201(){ } 公共布尔onKey(视图v、int keyCode、KeyEvent事件){ if(event.getAction()==1){ 试一试{ SettingAct_ViewHelper.this.ifc.setLoket(Integer.parseInt(((EditText)v.getText().toString()); }捕获(例外e){ } } 返回false; } } 类C04212实现OnKeyListener{ C04212(){ } 公共布尔onKey(视图v、int keyCode、KeyEvent事件){ if(event.getAction()==1){ 试一试{ SettingAct_ViewHelper.this.ifc.setAntrian(Integer.parseInt(((EditText)v.getText().toString()); }捕获(例外e){ } } 返回false; } } 类C04223实现OnItemSelectedListener{ C04223(){ } 已选择公共位置(AdapterView AdapterView、视图视图、整型位置、长id){ if(position!=SettingAct\u ViewHelper.this.ifc.getAppMode()){ SettingAct_ViewHelper.this.ifc.setAppMode(位置); } } 未选择公共无效(AdapterView AdapterView){ } } 类C04234实现OnKeyListener{ C04234(){ } 公共布尔onKey(视图v、int keyCode、KeyEvent事件){ 试一试{ if(event.getAction()==1){ EditText et=(EditText)v; 字符串text=et.getText().toString(); 如果(!text.startsWith(“http:/”){ text=“http://”+text; et.setText(文本); et.setSelection(text.length()); } SettingAct_ViewHelper.this.ifc.setServerAddress(文本); } }捕获(例外e){ } 返回false; } } 类C04245实现OnItemSelectedListener{ C04245(){ } 已选择公共位置(AdapterView AdapterView、视图视图、整型位置、长id){ int psoundat=position==0?AntrianConfig.M_客户端:AntrianConfig.M_服务器; if(psoundat!=SettingAct\u ViewHelper.this.ifc.getPlaysoundAt()){ SettingAct_ViewHelper.this.ifc.setPlaySoundAt(psoundat); SettingAct_ViewHelper.this.addAllsettingChild(); } } 未选择公共无效(AdapterView AdapterView){ } } 类C04256实现OnKeyListener{ C04256(){ } 公共布尔onKey(视图v、int keyCode、KeyEvent事件){ 试一试{ if(event.getAction()==1){ EditText et=(EditText)v; if(et.getText().toString().length()>=4){ SettingAct_ViewHelper.this.ifc.setServerPort(Integer.parseInt(et.getText().toString()); } } }捕获(例外e){ } 返回false; } } 类C04267实现OnClickListener{ C04267(){ } 公共void onClick(视图v){ Toast.makeText(setingact_ViewHelper.this.act,“Tutup and buka aplikasi untuk menyalakan server”,0).show(); } } 公共接口设置ActViewInterface{ int getAppMode(); int getCurrentAntrian(); int getLoket(); int getPlaysoundAt(); 字符串getServerAddress(); int getServerPort(); 塞坦提安语无效(int i); void setAppMode(int i); void setLoket(int i); void setPlaySoundAt(int i); 无效设置服务器地址(字符串str); 无效设置服务器端口(int i); } 类C06438实现MyClientCallback{ C06438(){ } 公开作废结果(int i){ 如果(i==200){ SettingAct_ViewHelper.this.tombolstatus.setOn(Boolean.valueOf(true)); }否则{ SettingAct_ViewHelper.this.tombolstatus.setOn(Boolean.valueOf(false)); } } 公共无效错误(字符串消息){ } } 公共设置Act_ViewHelper(活动actIn,设置ActViewInterface ifcIn){ this.act=actIn
FATAL EXCEPTION: main
Process: com.solusiwebmaster.antrian, PID: 22033
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.solusiwebmaster.antrian/com.solusiwebmaster.antrian.SettingAct}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.LayoutInflater android.app.Activity.getLayoutInflater()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.LayoutInflater android.app.Activity.getLayoutInflater()' on a null object reference
at com.solusiwebmaster.antrian.SettingAct_ViewHelper.<init>(SettingAct_ViewHelper.java:37)
at com.solusiwebmaster.antrian.SettingAct.onCreate(SettingAct.java:128)
at android.app.Activity.performCreate(Activity.java:6955)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6776) 
class ChildView {
    public View rootview=SettingAct_ViewHelper.this.inflater.inflate(R.layout.activity_setting_child, SettingAct_ViewHelper.this.table, false);
    public LinearLayout childlinear = ((LinearLayout) this.rootview.findViewById(R.id.asc_childLinear));       
    public TextView textview = ((TextView) this.rootview.findViewById(R.id.asc_text));
    public SmallTombolBulat tombol = ((SmallTombolBulat) this.rootview.findViewById(R.id.asc_tombol));