应用程序崩溃了

时间:2015-08-20 17:37:08

标签: java android eclipse

当我尝试运行我的应用时,我的应用崩溃了。它在日志文件中显示一些错误。以下是日志文件中显示的错误。

请帮助解决错误。

日志文件

08-20 23:04:41.766: E/AndroidRuntime(8695): FATAL EXCEPTION: main
08-20 23:04:41.766: E/AndroidRuntime(8695): Process: com.example.er.wolfpack, PID: 8695
08-20 23:04:41.766: E/AndroidRuntime(8695): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.er.wolfpack/com.example.er.wolfpack.MainActivity}: java.lang.NullPointerException
08-20 23:04:41.766: E/AndroidRuntime(8695):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at android.app.ActivityThread.access$800(ActivityThread.java:139)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at android.os.Handler.dispatchMessage(Handler.java:102)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at android.os.Looper.loop(Looper.java:149)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at android.app.ActivityThread.main(ActivityThread.java:5257)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at java.lang.reflect.Method.invokeNative(Native Method)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at java.lang.reflect.Method.invoke(Method.java:515)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at dalvik.system.NativeStart.main(Native Method)
08-20 23:04:41.766: E/AndroidRuntime(8695): Caused by: java.lang.NullPointerException
08-20 23:04:41.766: E/AndroidRuntime(8695):     at com.example.er.wolfpack.MainActivity.onCreate(MainActivity.java:26)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at android.app.Activity.performCreate(Activity.java:5411)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-20 23:04:41.766: E/AndroidRuntime(8695):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
08-20 23:04:41.766: E/AndroidRuntime(8695):     ... 11 more
public class MainActivity extends Activity implements View.OnClickListener {

ImageView im1;
TextView tv1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);


    tv1=(TextView)findViewById(R.id.textView1);
    im1=(ImageView)findViewById(R.id.imageView1);

    tv1.setOnClickListener(this);
    im1.setOnClickListener(this);
}

@Override
public void onClick(View v) {

    startActivity(new Intent(this,Login.class));

}
}

2 个答案:

答案 0 :(得分:0)

请检查mainactivity中的第26行看起来像一个引用为null。 Probobly findViewByid返回null。可能你提出错误的身份

答案 1 :(得分:0)

如果var dataChart = new gapi.analytics.googleCharts.DataChart({ query: { dimension: 'ga:dimension1', metrics: 'ga:pageview' }, chart: { container: 'chart-container', type: 'Table', options: { width: '100%' } } }); 为空,则表示使用的ids onCreate()textView1不存在于imageView1中的布局activity_login中。因此,请再次检查布局,因为您可能使用了错误的布局。