我正在为学校项目开发一个基本的Android应用程序。一切都工作正常,直到我放入一个新的类作为我的文件对象 - 我写入其变量,然后将对象保存到SD卡。但是我现在得到一个调试错误。它不包含对我自己的代码的任何引用 - 它似乎是指在启动活动时发生的事情,而不是在执行我的代码时。有什么建议?调试控制台中的错误消息如下:
Homework Planner [Android Application]
DalvikVM[localhost:8600]
Thread [<1> main] (Suspended (exception RuntimeException))
<VM does not provide monitor information>
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2194
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2229
ActivityThread.access$600(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 139
ActivityThread$H.handleMessage(Message) line: 1261
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 154
ActivityThread.main(String[]) line: 4945
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 511
ZygoteInit$MethodAndArgsCaller.run() line: 784
ZygoteInit.main(String[]) line: 551
NativeStart.main(String[]) line: not available [native method]
Thread [<10> Binder Thread #2] (Running)
Thread [<9> Binder Thread #1] (Running)
Daemon Thread [<8> FinalizerWatchdogDaemon] (Running)
Daemon Thread [<7> FinalizerDaemon] (Running)
Daemon Thread [<6> ReferenceQueueDaemon] (Running)
以下是活动开始的代码:
public class InputActivity extends Activity {
String chosenSubject = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_input);
// Set up the spinner and it's listener
Spinner subjectSpinner = (Spinner) findViewById(R.id.deadlinePicker);
subjectSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onNothingSelected(AdapterView<?> arg0) {}
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
chosenSubject = (String) arg0.getItemAtPosition(arg2);
}
});
// Set up save button
Button saveButton = (Button) findViewById(R.id.btnSave);
saveButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
//saveFile();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_input, menu);
return true;
}
答案 0 :(得分:0)
确保在清单文件中包含适当的权限,以便在SD卡中写入数据:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
还要确保将活动包含在清单文件中:
<activity android:name=".InputActivity"/>