これが以下のlogcatです。nullポインタの例外が何を意味するのか、またはその下にあるもののいずれかを理解できません。
08-18 14:59:21.080: E/AndroidRuntime(13333): FATAL EXCEPTION: main
08-18 14:59:21.080: E/AndroidRuntime(13333): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{k.t.m/k.t.m.MainActivity}: java.lang.NullPointerException
08-18 14:59:21.080: E/AndroidRuntime(13333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1894)
08-18 14:59:21.080: E/AndroidRuntime(13333): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
08-18 14:59:21.080: E/AndroidRuntime(13333): at android.app.ActivityThread.access$600(ActivityThread.java:128)
08-18 14:59:21.080: E/AndroidRuntime(13333): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
08-18 14:59:21.080: E/AndroidRuntime(13333): at android.os.Handler.dispatchMessage(Handler.java:99)
08-18 14:59:21.080: E/AndroidRuntime(13333): at android.os.Looper.loop(Looper.java:137)
08-18 14:59:21.080: E/AndroidRuntime(13333): at android.app.ActivityThread.main(ActivityThread.java:4514)
08-18 14:59:21.080: E/AndroidRuntime(13333): at java.lang.reflect.Method.invokeNative(Native Method)
08-18 14:59:21.080: E/AndroidRuntime(13333): at java.lang.reflect.Method.invoke(Method.java:511)
08-18 14:59:21.080: E/AndroidRuntime(13333): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
08-18 14:59:21.080: E/AndroidRuntime(13333): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
08-18 14:59:21.080: E/AndroidRuntime(13333): at dalvik.system.NativeStart.main(Native Method)
08-18 14:59:21.080: E/AndroidRuntime(13333): Caused by: java.lang.NullPointerException
08-18 14:59:21.080: E/AndroidRuntime(13333): at android.app.Activity.findViewById(Activity.java:1794)
08-18 14:59:21.080: E/AndroidRuntime(13333): at k.t.m.MainActivity.<init>(MainActivity.java:14)
08-18 14:59:21.080: E/AndroidRuntime(13333): at java.lang.Class.newInstanceImpl(Native Method)
08-18 14:59:21.080: E/AndroidRuntime(13333): at java.lang.Class.newInstance(Class.java:1319)
08-18 14:59:21.080: E/AndroidRuntime(13333): at android.app.Instrumentation.newActivity(Instrumentation.java:1027)
08-18 14:59:21.080: E/AndroidRuntime(13333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885)
08-18 14:59:21.080: E/AndroidRuntime(13333): ... 11 more
これが私がこれまでに持っている主なJavaです...この問題で私を助けてくれたみんなに感謝します。
package k.t.m;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.support.v4.app.NavUtils;
import android.widget.*;
public class MainActivity extends Activity {
TextView main = (TextView) findViewById(R.id.main);
Button mainButton1 = (Button) findViewById(R.id.mainButton1);
Button mainButton2 = (Button) findViewById(R.id.mainButton2);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainButton1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
milesToKilometers();
}
});
mainButton2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
kilometersToMiles();
}
});
}
protected void kilometersToMiles() {
main.setVisibility(View.INVISIBLE);
mainButton1.setVisibility(View.INVISIBLE);
mainButton2.setVisibility(View.INVISIBLE);
}
protected void milesToKilometers() {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}