こんにちは皆これは私の最初のAndroidアプリです。私はJavaとEclipseの初心者です。 私はこのプロジェクトを作成し、それを自分のデバイス(nexus)で実行しようとしました。これは私がLogCatで得るものです。致命的な例外:メイン
12-17 21:03:11.550: E/AndroidRuntime(20786): FATAL EXCEPTION: main
12-17 21:03:11.550: E/AndroidRuntime(20786): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gsmdata/com.example.gsmdata.GsmDataActivity}: java.lang.NullPointerException
12-17 21:03:11.550: E/AndroidRuntime(20786): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-17 21:03:11.550: E/AndroidRuntime(20786): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-17 21:03:11.550: E/AndroidRuntime(20786): at android.app.ActivityThread.access$1500 (ActivityThread.java:117)
12-17 21:03:11.550: E/AndroidRuntime(20786): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-17 21:03:11.550: E/AndroidRuntime(20786): at android.os.Handler.dispatchMessage(Handler.java:99)
12-17 21:03:11.550: E/AndroidRuntime(20786): at android.os.Looper.loop(Looper.java:130)
12-17 21:03:11.550: E/AndroidRuntime(20786): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-17 21:03:11.550: E/AndroidRuntime(20786): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 21:03:11.550: E/AndroidRuntime(20786): at java.lang.reflect.Method.invoke(Method.java:507)
12-17 21:03:11.550: E/AndroidRuntime(20786): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-17 21:03:11.550: E/AndroidRuntime(20786): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-17 21:03:11.550: E/AndroidRuntime(20786): at dalvik.system.NativeStart.main(Native Method)
12-17 21:03:11.550: E/AndroidRuntime(20786): Caused by: java.lang.NullPointerException
12-17 21:03:11.550: E/AndroidRuntime(20786): at com.example.gsmdata.GsmDataActivity.onCreate(GsmDataActivity.java:72)
12-17 21:03:11.550: E/AndroidRuntime(20786): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-17 21:03:11.550: E/AndroidRuntime(20786): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-17 21:03:11.550: E/AndroidRuntime(20786): ... 11 more
public class GsmDataActivity extends Activity {
/** Called when the activity is first created. */
int[] SignalStrength = {
-113,
-111,
-109,
-107,
-105,
-103,
-101,
-99,
-97,
-95,
-93,
-91,
-89,
-87,
-85,
-83,
-81,
-79,
-77,
-75,
-73,
-71,
-69,
-67,
-65,
-63,
-61,
-59,
-57,
-55,
-53,
-51};
int network_type,signal_strength,cid,Lac,bts;
TextView network, signal, ci, lac;
TelephonyManager phone;
GsmCellLocation cellId;
CdmaCellLocation baseStation;
SignalStrength phone_sig;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
network = (TextView) findViewById(R.id.tvNetwork);
signal =(TextView) findViewById(R.id.tvSignalValue);
ci = (TextView) findViewById(R.id.tvCiValue);
lac = (TextView) findViewById(R.id.tvLacValue);
network_type=phone.getNetworkType();
switch (network_type){
case 1: network.setText("GPRS");
case 3: network.setText("UMTS");
case 4: network.setText("CDMA");
case 8: network.setText("HSDPA");
case 9: network.setText("HSUPA");
case 10: network.setText("HSPA");
case 13: network.setText("LTE");
default: network.setText("UNKNOWN");
}
if (network_type==1){
signal_strength = phone_sig.getGsmSignalStrength();
signal.setText(SignalStrength[signal_strength] + "dBm");
cid= cellId.getCid();
Lac=cellId.getLac();
}
else if(network_type==0){
signal.setText("Unknown Network type");
}
else{
signal_strength= phone_sig.getCdmaDbm();
signal.setText(SignalStrength[signal_strength] + "dBm");
bts= baseStation.getBaseStationId();
Lac=cellId.getLac();
}
}
}
これは私のJavaクラスです。私はメインで致命的な例外を得る。どうしてか分かりません。手伝って頂けますか。前もって感謝します。次のXMLコードです:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width= "fill_parent"
android:layout_height="wrap_content"
android:textSize="50dp"
android:paddingBottom="5dp"
android:id="@+id/tvNetwork"
></TextView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/strength"
android:layout_gravity="center"
android:paddingBottom="5dp"
android:id="@+id/tvSignal"
/>
<TextView
android:layout_width= "fill_parent"
android:layout_height="wrap_content"
android:textSize="50dp"
android:paddingBottom="5dp"
android:gravity="center"
android:id="@+id/tvSignalValue"
></TextView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/cellid"
android:layout_gravity="center"
android:paddingBottom="5dp"
android:id="@+id/tvCi"
/>
<TextView
android:layout_width= "fill_parent"
android:layout_height="wrap_content"
android:textSize="50dp"
android:paddingBottom="5dp"
android:gravity="center"
android:id="@+id/tvCiValue"
></TextView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/lac"
android:layout_gravity="center"
android:id="@+id/tvLac"
/>
<TextView
android:layout_width= "fill_parent"
android:layout_height="wrap_content"
android:textSize="50dp"
android:paddingBottom="5dp"
android:gravity="center"
android:id="@+id/tvLacValue"
></TextView>
</LinearLayout>
ライン72は何ですか? >原因:com.example.gsmdata.GsmDataActivity.onCreate(GsmDataActivity.java:72)のjava.lang.NullPointerException NullPointerExceptionが存在します。 – Dante