NullPointerException on StartActivity (Android)?

The life cycle of an Activity in Android is handled automatically by the system. I mean ,you should not create a new instance of the GMSerial_CleanActivity Activity. You should call the output method directly.

Don't call GMSerial. Output .

Up vote 0 down vote favorite share g+ share fb share tw.

I know that similar questions have been asked, but having read through them it seems a wide array of things can be done wrong to cause this issue. And with this being my first real Android (and Java) application, I've probably done most of them. Thanks in advance for your help!

Stack (Logcat decided to randomly stop working in eclipse for some reason) Thread main (Suspended (exception NullPointerException)) GMSerial_CleanActivity(Activity). StartActivityForResult(Intent, int) line: 3190 GMSerial_CleanActivity(Activity). StartActivity(Intent) line: 3297 GMSerial_CleanActivity.

Output(String, String, String, TextView) line: 49 GMSerial_CleanActivity$1. OnCheckedChanged(CompoundButton, boolean) line: 35 ToggleButton(CompoundButton). SetChecked(boolean) line: 125 ToggleButton.

SetChecked(boolean) line: 72 ToggleButton(CompoundButton).toggle() line: 87 ToggleButton(CompoundButton).performClick() line: 99 View$PerformClick.run() line: 14105 ViewRootImpl(Handler). HandleCallback(Message) line: 605 ViewRootImpl(Handler). DispatchMessage(Message) line: 92 Looper.loop() line: 137 ActivityThread.

Main(String) line: 4424 Method. InvokeNative(Object, Object, Class, Class, Class, int, boolean) line: not available native method Method. Invoke(Object, Object...) line: 511 ZygoteInit$MethodAndArgsCaller.run() line: 784 ZygoteInit.

Main(String) line: 551 NativeStart. Main(String) line: not available native method Main Code package com. Greymatterrobotics.

Gmserial; import android.app. Activity; import android.content. Intent; import android.os.

Bundle; import android.widget. ToggleButton; import android.widget. TextView; import android.widget.

EditText; import android.widget. CheckBox; import android.widget. CompoundButton; public class GMSerial_CleanActivity extends Activity { static public final char cr = (char) 13; /** Called when the activity is first created.

*/ @Override public void onCreate(Bundle savedInstanceState) { final GMSerial_CleanActivity GMSerial = new GMSerial_CleanActivity(); super. OnCreate(savedInstanceState); setContentView(R.layout. Main); ToggleButton toggleSend = (ToggleButton) findViewById(R.id.

ToggleSend); final TextView textLog = (TextView) findViewById(R.id. TextLog); final EditText editBaud = (EditText) findViewById(R.id. EditBaud); final EditText editDelay = (EditText) findViewById(R.id.

EditDelay); //final CheckBox checkInvert = (CheckBox) findViewById(R.id. CheckInvert); toggleSend. SetOnCheckedChangeListener(new CompoundButton.

OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked){ GMSerial. Output(editBaud.getText().toString(), "getText().toString(), textLog); } } }); } public void output(String baud, String data, String delay, TextView log) { Intent serialout = new Intent(); serialout. SetClassName("com.

Greymatterrobotics. Gmserial", "com. Greymatterrobotics.gmserial.

Output"); serialout. PutExtra("BAUD", baud); serialout. PutExtra("DATA", data); serialout.

PutExtra("CHD", delay); startActivity(serialout); log. SetText(log.getText().toString() + cr + data); } } Output Code (By spiritplumberatgmail.com) package com. Greymatterrobotics.

Gmserial; import android.app. Activity; import android.os. Bundle; import android.os.

SystemClock; public class Output extends Activity { static public final char cr = (char) 13; // because I don't want to type that in every time static public final char lf = (char) 10; // because I don't want to type that in every time public String datatosend = ""; @Override public void onCreate(Bundle savedInstanceState) { AudioSerialOutMono.activate(); try{ Bundle bundle = getIntent().getExtras(); if (bundle. ContainsKey("BAUD")) AudioSerialOutMono. New_baudRate = Integer.

ParseInt(bundle. GetString("BAUD")); if (bundle. ContainsKey("CHD")) AudioSerialOutMono.

New_characterdelay = Integer. ParseInt(bundle. GetString("CHD")); if (bundle.

ContainsKey("DATA")) datatosend = (bundle. GetString("DATA")); AudioSerialOutMono. UpdateParameters(true); AudioSerialOutMono.

Output(datatosend+cr+lf); while (AudioSerialOutMono.isPlaying()) { SystemClock. Sleep(50); } }catch(Exception e){e.printStackTrace();} // android.os.Process. KillProcess(android.os.Process.myPid()); // NUKE super.

OnCreate(savedInstanceState); this.finish(); } } AndroidManifest. Xml java android android-intent android-activity link|improve this question asked Feb 4 at 0:16egg65131.

The life cycle of an Activity in Android is handled automatically by the system. I mean ,you should not create a new instance of the GMSerial_CleanActivity Activity. You should call the output method directly.

Don't call GMSerial.output. Also, in the output method, I prefer to using the code below to start a new activity(your code snippet may be right. I dont' have Eclipse on hand and thus can't test it).

Intent serialout = new Intent(); serialout. SetClass(this, Output. Class).

Try not having the MAIN intent filter on both activities.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions