私はAndroid開発の「TheNewBoston」からこのシリーズに参加していますが、エラー(NullPointerExceptionだと思います)が発生し、これを解決する方法がわからないため、49番目のビデオで立ち往生しています。アプリのテストは、eclipseのandroidエミュレーター5554:droidXで行われます。
package bogdy2p.ro.clicknet.web;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class OpenedClass extends Activity implements OnClickListener,OnCheckedChangeListener {
TextView question, test;
Button returnData;
RadioGroup selectionList;
String gotBread;
String setData;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.send);
initialize();
Bundle gotBasket = getIntent().getExtras();
gotBread = gotBasket.getString("key");
question.setText(gotBread);
}
private void initialize() {
// TODO Auto-generated method stub
question = (TextView) findViewById(R.id.tvQuestion);
test = (TextView) findViewById(R.id.tvText);
returnData = (Button) findViewById(R.id.bReturn);
returnData.setOnClickListener(this);
selectionList = (RadioGroup) findViewById(R.id.rgAnswers);
selectionList.setOnCheckedChangeListener(this);
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
switch (arg1) {
case R.id.rCrazy:
setData = "Probably right!";
break;
case R.id.rSexy:
setData = "Definetly right!";
break;
case R.id.rBoth:
setData = "Spot On!";
break;
}
test.setText(setData);
}
}
LogCat Eclipseからここに:
10-29 00:43:45.111: E/AndroidRuntime(637): FATAL EXCEPTION: main
10-29 00:43:45.111: E/AndroidRuntime(637): java.lang.RuntimeException: Unable to start activity ComponentInfo{bogdy2p.ro.clicknet.web/bogdy2p.ro.clicknet.web.OpenedClass}: java.lang.NullPointerException
10-29 00:43:45.111: E/AndroidRuntime(637): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-29 00:43:45.111: E/AndroidRuntime(637): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-29 00:43:45.111: E/AndroidRuntime(637): at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-29 00:43:45.111: E/AndroidRuntime(637): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-29 00:43:45.111: E/AndroidRuntime(637): at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 00:43:45.111: E/AndroidRuntime(637): at android.os.Looper.loop(Looper.java:137)
10-29 00:43:45.111: E/AndroidRuntime(637): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-29 00:43:45.111: E/AndroidRuntime(637): at java.lang.reflect.Method.invokeNative(Native Method)
10-29 00:43:45.111: E/AndroidRuntime(637): at java.lang.reflect.Method.invoke(Method.java:511)
10-29 00:43:45.111: E/AndroidRuntime(637): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-29 00:43:45.111: E/AndroidRuntime(637): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-29 00:43:45.111: E/AndroidRuntime(637): at dalvik.system.NativeStart.main(Native Method)
10-29 00:43:45.111: E/AndroidRuntime(637): Caused by: java.lang.NullPointerException
10-29 00:43:45.111: E/AndroidRuntime(637): at bogdy2p.ro.clicknet.web.OpenedClass.onCreate(OpenedClass.java:27)
10-29 00:43:45.111: E/AndroidRuntime(637): at android.app.Activity.performCreate(Activity.java:5008)
10-29 00:43:45.111: E/AndroidRuntime(637): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-29 00:43:45.111: E/AndroidRuntime(637): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-29 00:43:45.111: E/AndroidRuntime(637): ... 11 more
ここにManifest.Xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bogdy2p.ro.clicknet.web"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="bogdy2p.ro.clicknet.web.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="bogdy2p.ro.clicknet.web.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TextPlay"
android:label="@string/app_name" >
</activity>
<activity
android:name=".Email"
android:label="@string/app_name" >
</activity>
<activity
android:name=".Camera"
android:label="Camera Application"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".Data"
android:label="Data Application" >
</activity>
<activity
android:name=".OpenedClass"
android:label="Opened Class" >
</activity>
</application>
そしてここのData.javaクラス:
package bogdy2p.ro.clicknet.web;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Data extends Activity implements OnClickListener {
Button start, startFor;
EditText sendET;
TextView gotAnswer;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.get);
}
private void initialize() {
start = (Button) findViewById(R.id.bSA);
startFor = (Button) findViewById(R.id.bSAFR);
sendET = (EditText) findViewById(R.id.etSend);
gotAnswer = (TextView) findViewById(R.id.tvGot);
start.setOnClickListener(this);
startFor.setOnClickListener(this);
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()) {
case R.id.bSA:
String bread = sendET.getText().toString();
Bundle basket = new Bundle();
basket.putString("key", bread);
Intent a = new Intent(Data.this, OpenedClass.class);
a.putExtras(basket);
startActivity(a);
break;
case R.id.bSAFR:
Intent i = new Intent(Data.this, OpenedClass.class);
startActivityForResult(i, 0);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
}
}
LogCatを読み取る限り、問題はOpenedClass.javaファイルの@行27になりますが、問題が何であるかを理解できません。私のプログラムはビデオのものと同じですが、私のプログラムは機能せず、ビデオではプログラムは正常に実行されます。