java.lang.RuntimeException: Unable to instantiate activity ComponentInfo

前端 未结 30 2664
感动是毒
感动是毒 2020-11-22 15:15

I was trying to run a sample code While launching the application in the android 1.5 emulator , I got these errors.... Any one have some hint..?

ERROR from LogCat:<

30条回答
  •  时光取名叫无心
    2020-11-22 15:55

    You may be trying to find the view before onCreate() which is incorrect.

    public class MainActivity extends Activity {
    
      ImageView mainImage = (ImageView) findViewById(R.id.imageViewMain); //incorrect
    
      @Override
      protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
      }
      ...
    }
    

提交回复
热议问题