0

hi ive started an app and wanted to test it so i use an avd and when the app starts it crashes and i was hoping somebody could help

this is my java class

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MemoryInfo mi = new MemoryInfo();
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    activityManager.getMemoryInfo(mi);
    long availableMegs = mi.availMem / 1048576L;

    TextView manufacturerTextView = (TextView)findViewById(R.id.mem);
    manufacturerTextView.setText((int) mi.availMem);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

LOGCAT

02-06 07:10:05.202: E/AndroidRuntime(771): FATAL EXCEPTION: main 02-06 07:10:05.202: E/AndroidRuntime(771): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.MainActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x18184000 02-06 07:10:05.202: E/AndroidRuntime(771): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 02-06 07:10:05.202: E/AndroidRuntime(771): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 02-06 07:10:05.202: E/AndroidRuntime(771): at android.app.ActivityThread.access$600(ActivityThread.java:141) 02-06 07:10:05.202: E/AndroidRuntime(771): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)

user1934637
  • 25
  • 1
  • 1
  • 8

2 Answers2

3

use

manufacturerTextView.setText(String.valueOf((int) mi.availMem));

instead

manufacturerTextView.setText((int) mi.availMem);

for showing Integer value in TextView

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • i cant put up logcat its to long – user1934637 Feb 06 '13 at 07:08
  • Only put up the part showing the crash. If you don't know how, then learn about how Android uses logcat first. http://stackoverflow.com/questions/8217500/how-to-print-stacktrace-for-an-exception-android – Simon Feb 06 '13 at 07:16
  • @user1934637 : you are getting error because of `manufacturerTextView.setText((int) mi.availMem);` line – ρяσѕρєя K Feb 06 '13 at 07:29
  • @user1934637 : use `manufacturerTextView.setText(String.valueOf(mi.availMem));` instead of `manufacturerTextView.setText((int) mi.availMem);` – ρяσѕρєя K Feb 06 '13 at 07:31
  • @user1934637 : any success ? – ρяσѕρєя K Feb 06 '13 at 07:37
  • ok it worked but why is it giving me a 9 digit number.is that kilobytes or somthing – user1934637 Feb 06 '13 at 07:37
  • @ρяσѕρєя K it worked but how can i turn the avalible memory into MB format – user1934637 Feb 06 '13 at 07:41
  • @user1934637 : i think u will need to show `availableMegs` in TextView instead of `mi.availMem` – ρяσѕρєя K Feb 06 '13 at 07:44
  • @user1934637 : and also check [this](http://orion-viewer.googlecode.com/git-history/b4486e05aeb9bb114778d7a5be3052b9f04a00ba/orion_viewer/src/universe/constellation/orion/viewer/prefs/DevicePrefInfo.java) example for showing availMem in Mb – ρяσѕρєя K Feb 06 '13 at 07:48
  • ok it worked thanks for all the help but i need just one last thing.How to i get the total device ram and just not the avaliable memory – user1934637 Feb 06 '13 at 07:50
  • @user1934637 : friend just make a search lots of previously question available on same . if after searching u are not able to find any solution then comment me or make a new question for other issue then i will try to help u . – ρяσѕρєя K Feb 06 '13 at 07:54
  • @user1934637 : have u see [this](http://stackoverflow.com/questions/10935022/android-how-to-get-memory-usage-of-my-android-device) post ? – ρяσѕρєя K Feb 06 '13 at 08:00
0

convert it to string to display

saran
  • 461
  • 1
  • 6
  • 20