インテントから返された文字列から switch ステートメントを作成しようとしています
public class ContactDetailsActivity extends Activity {
String address;
String hours;
String name;
TextView textview;
String Zero = "0";
String One = "1";
String Two = "2";
String Three = "3";
String Four = "4";
Intent receivedIntent = getIntent();
String myUrl = receivedIntent.getStringExtra("key");
public void main(String myUrl){
Log.v("myUrl", myUrl);
String locations = myUrl;
locationsNum location = locationsNum.valueOf(locations);
switch(location) {
case Zero:
textview.setText("Got it");
textview.setText("It Worked!!");
break;
}
}
public enum locationsNum {
Zero,
One,
Two,
Three,
Four
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
textview = new TextView(this);
textview.setText("This is the Contact tab");
//Intent receivedIntent = getIntent();
//String myUrl = receivedIntent.getStringExtra("key");
// Toast.makeText(this, myUrl, Toast.LENGTH_SHORT).show();
}
返されるデータはインデックス値「0 - 4」で、テスト用に myUrl に入れています。Instatiate アクティビティ エラーが発生します。
私がやっていることはすべて間違っていますか、それとも何かが足りないだけですか?
ご協力いただきありがとうございます!
エラーログはこちら
04-18 11:47:59.402: E/AndroidRuntime(1383): FATAL EXCEPTION: main
04-18 11:47:59.402: E/AndroidRuntime(1383): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mlgw.mlgwapp/com.mlgw.mlgwapp.ContactDetailsActivity}: java.lang.NullPointerException
04-18 11:47:59.402: E/AndroidRuntime(1383): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
04-18 11:47:59.402: E/AndroidRuntime(1383): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-18 11:47:59.402: E/AndroidRuntime(1383): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-18 11:47:59.402: E/AndroidRuntime(1383): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-18 11:47:59.402: E/AndroidRuntime(1383): at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 11:47:59.402: E/AndroidRuntime(1383): at android.os.Looper.loop(Looper.java:130)
04-18 11:47:59.402: E/AndroidRuntime(1383): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-18 11:47:59.402: E/AndroidRuntime(1383): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 11:47:59.402: E/AndroidRuntime(1383): at java.lang.reflect.Method.invoke(Method.java:507)
04-18 11:47:59.402: E/AndroidRuntime(1383): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-18 11:47:59.402: E/AndroidRuntime(1383): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-18 11:47:59.402: E/AndroidRuntime(1383): at dalvik.system.NativeStart.main(Native Method)
04-18 11:47:59.402: E/AndroidRuntime(1383): Caused by: java.lang.NullPointerException
04-18 11:47:59.402: E/AndroidRuntime(1383): at com.mlgw.mlgwapp.ContactDetailsActivity.<init>(ContactDetailsActivity.java:23)
04-18 11:47:59.402: E/AndroidRuntime(1383): at java.lang.Class.newInstanceImpl(Native Method)
04-18 11:47:59.402: E/AndroidRuntime(1383): at java.lang.Class.newInstance(Class.java:1409)
04-18 11:47:59.402: E/AndroidRuntime(1383): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-18 11:47:59.402: E/AndroidRuntime(1383): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
04-18 11:47:59.402: E/AndroidRuntime(1383): ... 11 more