私は同様の質問がされていることを知っていますが、この問題を引き起こすためにさまざまなことが間違っているようです。そして、これが私の最初の本当のAndroid(およびJava)アプリケーションであることから、私はおそらくそれらのほとんどをやってきました。あなたの助けを前もってありがとう!StartActivity(Android)のNullPointerException
スタック[の] spiritplumberことで
Thread [<1> 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]
メインコード
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(), "Hello World", editDelay.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);
}
}
出力コード((Logcatはランダムに何らかの理由で日食に作業を停止することを決めました) gmail.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
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.greymatterrobotics.gmserial"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".GMSerial_CleanActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Output"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>