你好我开始了一个应用程序并想测试它所以我使用avd当应用程序启动它崩溃,我希望有人可以帮助
这是我的java类
@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):致命异常:主要 02-06 07:10:05.202:E / AndroidRuntime(771):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.test / com.example.test.MainActivity}:android.content.res.Resources $ NotFoundException:字符串资源ID#0x18184000 02-06 07:10:05.202:E / AndroidRuntime(771):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 02-06 07:10:05.202:E / AndroidRuntime(771):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 02-06 07:10:05.202:E / AndroidRuntime(771):在android.app.ActivityThread.access $ 600(ActivityThread.java:141) 02-06 07:10:05.202:E / AndroidRuntime(771):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234)
答案 0 :(得分:3)
使用
manufacturerTextView.setText(String.valueOf((int) mi.availMem));
而不是
manufacturerTextView.setText((int) mi.availMem);
用于在TextView中显示Integer值
答案 1 :(得分:0)
将其转换为字符串以显示