java - Why MainActivity cannot be resolved or is not a field? -


I have a small project where I have to play with an Android device's battery. First, I wanted to be able to print the battery so I used it.

Again, I have created a new Android project called "Trial" in Eclipse, and in the main activity. Java I have put this code:

  package com.example.testing; Import android App Import android.content.BroadcastReceiver; Import android.content.Context; Import android.content.Intent; Import android.content.IntentFilter; Android Import Battery Manager; Importroid.os.Bundle; Import android.util.log; Import android.view.View; Import android.view.View.OnClickListener; Import android.widget.TextView; Import android.widget.Toast; Android Import * r *; Public class increases main activity activity (text view mTextView; @ override protected void creatives (bundle saved instenstate) {super.Nocrat (savedinstenstate); setContentView (R.layout.MainActivity); // This is main activity In which error is mTextView = (TextView) findViewById (R.id.batterTest); findViewById (R.id.getBattery) .setOnClickListener (New OnClickListener) {@Override Public Zero onClick (see v) {mTextView.setText (String.valueOf (BatteryLevel);}}); New thread (new thread) (); Start ();} @ Override protection Destroy () {Super. Onesteroy (); unregisterReceiver (medulla);} Battery Receiver Miro; Private Class Thread M implements Runnable {@Override public void run () {mArrow = new BatteryReceiver (); IntentFilter mIntentFilter = New InterFilters (); mIntentFilter.addAction (Intent.ACTION_BATTERY_LOW); mIntentFilter.addAction (Intent.ACTION_BATTERY_CHANGED); mIntentFilter.addAction (Intent.ACTION_BATTERY_OKAY); Intent BatteryInantent = Register Receiver (MyOo, MIent Filters); Battery level = getting (batteryinentent); Logs. E ("battery level", string.value (battery level)); }} Float battery level; The Private Class Battery Receiver Expands Broadcast Receiver {@Orreide Public Records on Receive (Reference ARB0, Intent arg1) {if (arg1.getAction ()) is equal to IgnoreCase (Intent.ACTION_BATTERY_LOW) || Arg1.getAction () Equal IgnoreCase (Intent.ACTION_BATTERY_CHANGED) || Arg1 .getAction (). Equivalent ignore CAS (Intent.ACTION_BATTERY_OKAY)) {int level = arg1.getIntExtra ("Level", 0); Toast. Make Text (main activity., "Current battery" + Level + "%", Toast. LNNHHLANG). Show (); MTextView.setText (String.valueOf ("Battery Level Replace Find By Receiver" = Level)); }}} Public name getBatteryLevel (intent batteryIntent) {int level = batteryIntent.getIntExtra (BatteryManager.EXTRA_LEVEL, -1); Int scale = batteryinentant.getinet extra (battery manager. EXTRA_SCALE, -1); If (level == -1 || scale == -1) {return 50.0f; } Return (float) level / (float) scale) * 100.0F; }}  

Actually it should run a simple activity just with the battery level printed on the screen. But this is not due to an error "main activity can not be solved or there is no area" (see the comment line). Do you have any ideas? I would like to thank if this code is working so I can go on then.

"itemprop =" text ">

after you

change the setContentView (R.layout.MainActivity) the wanted;

  setContentView (R.layout.activity_main);  

Think you are called a layout activity_main.xml and not MainActivity which is actually the name of your activity class

Remove more

  Import Android. R. *;  

Import more

  import com.example.testing.R;  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -