我是android的初学者,在列表视图中打开文本文件时遇到一些问题:
package com.example.androidexplorer;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Intent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class MainActivity extends ListActivity {
private List<String> item = null;
private List<String> path = null;
private String root;
private TextView myPath;
SaveString saveStr = new SaveString();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myPath = (TextView)findViewById(R.id.path);
root = Environment.getExternalStorageDirectory().getPath();
getDir(root);
}
private void getDir(String dirPath)
{
myPath.setText("Location: " + dirPath);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if(!dirPath.equals(root))
{
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for(int i=0; i < files.length; i++)
{
File file = files[i];
if(!file.isHidden() && file.canRead()){
path.add(file.getPath());
if(file.isDirectory()){
item.add(file.getName() + "/");
}else{
item.add(file.getName());
}
}
saveStr.savePathString = file.getName();
}
ArrayAdapter<String> fileList =
new ArrayAdapter<String>(this, R.layout.row, item);
setListAdapter(fileList);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
File file = new File(path.get(position));
if (file.isDirectory())
{
if(file.canRead()){
getDir(path.get(position));
}else{
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("[" + file.getName() + "] folder can't be read!")
.setPositiveButton("OK", null).show();
}
saveStr.savePathString = file.getName();
}else {
Intent intent1 = new Intent(MainActivity.this, ReadActivity.class);
startActivity(intent1);
/*new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("[" + file.getName() + "]")
.setPositiveButton("OK", null).show();*/
}
}
}
ReadActivity此类在textView上显示选定的文本文件
package com.example.androidexplorer;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.TextView;
public class ReadActivity extends Activity{
TextView textView;
SaveString saveStr = new SaveString();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.read);
//textView = (TextView)findViewById(R.id.textView1);
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File file = new File(sdcard, saveStr.savePathString);
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}
//Find the view by its id
TextView tv = (TextView)findViewById(R.id.textView1);
tv.setText(text);
}
}
当我在列表视图中单击文本文件时,我的程序停止了。我不明白为什么?
堆栈追踪:
01-07 10:40:21.250: I/Process(847): Sending signal. PID: 847 SIG: 9
01-07 10:40:34.110: D/AbsListView(1481): Get MotionRecognitionManager
01-07 10:40:34.200: D/libEGL(1481): loaded /system/lib/egl/libEGL_mali.so
01-07 10:40:34.210: D/libEGL(1481): loaded /system/lib/egl/libGLESv1_CM_mali.so
01-07 10:40:34.210: D/libEGL(1481): loaded /system/lib/egl/libGLESv2_mali.so
01-07 10:40:34.230: D/OpenGLRenderer(1481): Enabling debug mode 0
01-07 10:40:40.780: E/InputEventReceiver(1481): Exception dispatching input event.
01-07 10:40:40.780: E/MessageQueue-JNI(1481): Exception in MessageQueue callback: handleReceiveCallback
01-07 10:40:40.870: E/MessageQueue-JNI(1481): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.androidexplorer/com.example.androidexplorer.ReadActivity}; have you declared this activity in your AndroidManifest.xml?
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1556)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.app.Activity.startActivityForResult(Activity.java:3428)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.app.Activity.startActivityForResult(Activity.java:3389)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.app.Activity.startActivity(Activity.java:3599)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.app.Activity.startActivity(Activity.java:3567)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at com.example.androidexplorer.MainActivity.onListItemClick(MainActivity.java:97)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.widget.AdapterView.performItemClick(AdapterView.java:301)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.widget.AbsListView.performItemClick(AbsListView.java:1287)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3078)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.widget.AbsListView.onTouchEvent(AbsListView.java:4174)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.View.dispatchTouchEvent(View.java:7379)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2462)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2195)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2468)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2210)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2468)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2210)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2468)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2210)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2468)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2210)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2177)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1482)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.app.Activity.dispatchTouchEvent(Activity.java:2469)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2125)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.View.dispatchPointerEvent(View.java:7564)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3543)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3475)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4585)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4563)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4667)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.os.MessageQueue.nativePollOnce(Native Method)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.os.MessageQueue.next(MessageQueue.java:125)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.os.Looper.loop(Looper.java:124)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at android.app.ActivityThread.main(ActivityThread.java:4944)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at java.lang.reflect.Method.invokeNative(Native Method)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at java.lang.reflect.Method.invoke(Method.java:511)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-07 10:40:40.870: E/MessageQueue-JNI(1481): at dalvik.system.NativeStart.main(Native Method)
01-07 10:40:40.880: D/AndroidRuntime(1481): Shutting down VM
01-07 10:40:40.880: W/dalvikvm(1481): threadid=1: thread exiting with uncaught exception (group=0x40fe02b8)
01-07 10:40:40.890: E/AndroidRuntime(1481): FATAL EXCEPTION: main
01-07 10:40:40.890: E/AndroidRuntime(1481): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.androidexplorer/com.example.androidexplorer.ReadActivity}; have you declared this activity in your AndroidManifest.xml?
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1556)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.app.Activity.startActivityForResult(Activity.java:3428)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.app.Activity.startActivityForResult(Activity.java:3389)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.app.Activity.startActivity(Activity.java:3599)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.app.Activity.startActivity(Activity.java:3567)
01-07 10:40:40.890: E/AndroidRuntime(1481): at com.example.androidexplorer.MainActivity.onListItemClick(MainActivity.java:97)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.widget.AdapterView.performItemClick(AdapterView.java:301)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.widget.AbsListView.performItemClick(AbsListView.java:1287)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3078)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.widget.AbsListView.onTouchEvent(AbsListView.java:4174)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.View.dispatchTouchEvent(View.java:7379)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2462)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2195)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2468)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2210)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2468)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2210)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2468)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2210)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2468)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2210)
01-07 10:40:40.890: E/AndroidRuntime(1481): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2177)
01-07 10:40:40.890: E/AndroidRuntime(1481): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1482)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.app.Activity.dispatchTouchEvent(Activity.java:2469)
01-07 10:40:40.890: E/AndroidRuntime(1481): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2125)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.View.dispatchPointerEvent(View.java:7564)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3543)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3475)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4585)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4563)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4667)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.os.MessageQueue.nativePollOnce(Native Method)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.os.MessageQueue.next(MessageQueue.java:125)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.os.Looper.loop(Looper.java:124)
01-07 10:40:40.890: E/AndroidRuntime(1481): at android.app.ActivityThread.main(ActivityThread.java:4944)
01-07 10:40:40.890: E/AndroidRuntime(1481): at java.lang.reflect.Method.invokeNative(Native Method)
01-07 10:40:40.890: E/AndroidRuntime(1481): at java.lang.reflect.Method.invoke(Method.java:511)
01-07 10:40:40.890: E/AndroidRuntime(1481): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-07 10:40:40.890: E/AndroidRuntime(1481): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-07 10:40:40.890: E/AndroidRuntime(1481): at dalvik.system.NativeStart.main(Native Method)
最后一次logcat错误:
01-07 11:03:47.510: I/Process(2299): Sending signal. PID: 2299 SIG: 9
01-07 11:04:12.710: D/AbsListView(2598): Get MotionRecognitionManager
01-07 11:04:12.820: D/libEGL(2598): loaded /system/lib/egl/libEGL_mali.so
01-07 11:04:12.830: D/libEGL(2598): loaded /system/lib/egl/libGLESv1_CM_mali.so
01-07 11:04:12.830: D/libEGL(2598): loaded /system/lib/egl/libGLESv2_mali.so
01-07 11:04:12.850: D/OpenGLRenderer(2598): Enabling debug mode 0
01-07 11:04:16.080: D/AndroidRuntime(2598): Shutting down VM
01-07 11:04:16.080: W/dalvikvm(2598): threadid=1: thread exiting with uncaught exception (group=0x40fe02b8)
01-07 11:04:16.150: E/AndroidRuntime(2598): FATAL EXCEPTION: main
01-07 11:04:16.150: E/AndroidRuntime(2598): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidexplorer/com.example.androidexplorer.ReadActivity}: java.lang.NullPointerException
01-07 11:04:16.150: E/AndroidRuntime(2598): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
01-07 11:04:16.150: E/AndroidRuntime(2598): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
01-07 11:04:16.150: E/AndroidRuntime(2598): at android.app.ActivityThread.access$700(ActivityThread.java:140)
01-07 11:04:16.150: E/AndroidRuntime(2598): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
01-07 11:04:16.150: E/AndroidRuntime(2598): at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 11:04:16.150: E/AndroidRuntime(2598): at android.os.Looper.loop(Looper.java:137)
01-07 11:04:16.150: E/AndroidRuntime(2598): at android.app.ActivityThread.main(ActivityThread.java:4944)
01-07 11:04:16.150: E/AndroidRuntime(2598): at java.lang.reflect.Method.invokeNative(Native Method)
01-07 11:04:16.150: E/AndroidRuntime(2598): at java.lang.reflect.Method.invoke(Method.java:511)
01-07 11:04:16.150: E/AndroidRuntime(2598): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-07 11:04:16.150: E/AndroidRuntime(2598): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-07 11:04:16.150: E/AndroidRuntime(2598): at dalvik.system.NativeStart.main(Native Method)
01-07 11:04:16.150: E/AndroidRuntime(2598): Caused by: java.lang.NullPointerException
01-07 11:04:16.150: E/AndroidRuntime(2598): at java.io.File.<init>(File.java:150)
01-07 11:04:16.150: E/AndroidRuntime(2598): at java.io.File.<init>(File.java:124)
01-07 11:04:16.150: E/AndroidRuntime(2598): at com.example.androidexplorer.ReadActivity.onCreate(ReadActivity.java:29)
01-07 11:04:16.150: E/AndroidRuntime(2598): at android.app.Activity.performCreate(Activity.java:5188)
01-07 11:04:16.150: E/AndroidRuntime(2598): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
01-07 11:04:16.150: E/AndroidRuntime(2598): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2085)
01-07 11:04:16.150: E/AndroidRuntime(2598): ... 11 more
新的logcat错误:
01-07 11:27:01.680: D/AbsListView(3072): Get MotionRecognitionManager
01-07 11:27:01.920: D/libEGL(3072): loaded /system/lib/egl/libEGL_mali.so
01-07 11:27:01.960: D/libEGL(3072): loaded /system/lib/egl/libGLESv1_CM_mali.so
01-07 11:27:01.970: D/libEGL(3072): loaded /system/lib/egl/libGLESv2_mali.so
01-07 11:27:02.020: D/OpenGLRenderer(3072): Enabling debug mode 0
01-07 11:27:10.540: D/AbsListView(3286): Get MotionRecognitionManager
01-07 11:27:10.770: D/libEGL(3286): loaded /system/lib/egl/libEGL_mali.so
01-07 11:27:10.770: D/libEGL(3286): loaded /system/lib/egl/libGLESv1_CM_mali.so
01-07 11:27:10.780: D/libEGL(3286): loaded /system/lib/egl/libGLESv2_mali.so
01-07 11:27:10.800: D/OpenGLRenderer(3286): Enabling debug mode 0
01-07 11:27:21.700: D/AndroidRuntime(3286): Shutting down VM
01-07 11:27:21.700: W/dalvikvm(3286): threadid=1: thread exiting with uncaught exception (group=0x40fe02b8)
01-07 11:27:21.710: E/AndroidRuntime(3286): FATAL EXCEPTION: main
01-07 11:27:21.710: E/AndroidRuntime(3286): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidexplorer/com.example.androidexplorer.ReadActivity}: java.lang.NullPointerException
01-07 11:27:21.710: E/AndroidRuntime(3286): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
01-07 11:27:21.710: E/AndroidRuntime(3286): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
01-07 11:27:21.710: E/AndroidRuntime(3286): at android.app.ActivityThread.access$700(ActivityThread.java:140)
01-07 11:27:21.710: E/AndroidRuntime(3286): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
01-07 11:27:21.710: E/AndroidRuntime(3286): at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 11:27:21.710: E/AndroidRuntime(3286): at android.os.Looper.loop(Looper.java:137)
01-07 11:27:21.710: E/AndroidRuntime(3286): at android.app.ActivityThread.main(ActivityThread.java:4944)
01-07 11:27:21.710: E/AndroidRuntime(3286): at java.lang.reflect.Method.invokeNative(Native Method)
01-07 11:27:21.710: E/AndroidRuntime(3286): at java.lang.reflect.Method.invoke(Method.java:511)
01-07 11:27:21.710: E/AndroidRuntime(3286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-07 11:27:21.710: E/AndroidRuntime(3286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-07 11:27:21.710: E/AndroidRuntime(3286): at dalvik.system.NativeStart.main(Native Method)
01-07 11:27:21.710: E/AndroidRuntime(3286): Caused by: java.lang.NullPointerException
01-07 11:27:21.710: E/AndroidRuntime(3286): at java.io.File.<init>(File.java:150)
01-07 11:27:21.710: E/AndroidRuntime(3286): at java.io.File.<init>(File.java:124)
01-07 11:27:21.710: E/AndroidRuntime(3286): at com.example.androidexplorer.ReadActivity.onCreate(ReadActivity.java:32)
01-07 11:27:21.710: E/AndroidRuntime(3286): at android.app.Activity.performCreate(Activity.java:5188)
01-07 11:27:21.710: E/AndroidRuntime(3286): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
01-07 11:27:21.710: E/AndroidRuntime(3286): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2085)
01-07 11:27:21.710: E/AndroidRuntime(3286): ... 11 more
01-07 11:27:28.870: I/Process(3286): Sending signal. PID: 3286 SIG: 9
01-07 11:29:07.870: D/AbsListView(3485): Get MotionRecognitionManager
01-07 11:29:08.060: D/libEGL(3485): loaded /system/lib/egl/libEGL_mali.so
01-07 11:29:08.060: D/libEGL(3485): loaded /system/lib/egl/libGLESv1_CM_mali.so
01-07 11:29:08.080: D/libEGL(3485): loaded /system/lib/egl/libGLESv2_mali.so
01-07 11:29:08.130: D/OpenGLRenderer(3485): Enabling debug mode 0
01-07 11:29:13.360: D/AndroidRuntime(3485): Shutting down VM
01-07 11:29:13.360: W/dalvikvm(3485): threadid=1: thread exiting with uncaught exception (group=0x40fe02b8)
01-07 11:29:13.370: E/AndroidRuntime(3485): FATAL EXCEPTION: main
01-07 11:29:13.370: E/AndroidRuntime(3485): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidexplorer/com.example.androidexplorer.ReadActivity}: java.lang.NullPointerException
01-07 11:29:13.370: E/AndroidRuntime(3485): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
01-07 11:29:13.370: E/AndroidRuntime(3485): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
01-07 11:29:13.370: E/AndroidRuntime(3485): at android.app.ActivityThread.access$700(ActivityThread.java:140)
01-07 11:29:13.370: E/AndroidRuntime(3485): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
01-07 11:29:13.370: E/AndroidRuntime(3485): at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 11:29:13.370: E/AndroidRuntime(3485): at android.os.Looper.loop(Looper.java:137)
01-07 11:29:13.370: E/AndroidRuntime(3485): at android.app.ActivityThread.main(ActivityThread.java:4944)
01-07 11:29:13.370: E/AndroidRuntime(3485): at java.lang.reflect.Method.invokeNative(Native Method)
01-07 11:29:13.370: E/AndroidRuntime(3485): at java.lang.reflect.Method.invoke(Method.java:511)
01-07 11:29:13.370: E/AndroidRuntime(3485): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-07 11:29:13.370: E/AndroidRuntime(3485): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-07 11:29:13.370: E/AndroidRuntime(3485): at dalvik.system.NativeStart.main(Native Method)
01-07 11:29:13.370: E/AndroidRuntime(3485): Caused by: java.lang.NullPointerException
01-07 11:29:13.370: E/AndroidRuntime(3485): at java.io.File.<init>(File.java:150)
01-07 11:29:13.370: E/AndroidRuntime(3485): at java.io.File.<init>(File.java:124)
01-07 11:29:13.370: E/AndroidRuntime(3485): at com.example.androidexplorer.ReadActivity.onCreate(ReadActivity.java:33)
01-07 11:29:13.370: E/AndroidRuntime(3485): at android.app.Activity.performCreate(Activity.java:5188)
01-07 11:29:13.370: E/AndroidRuntime(3485): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
01-07 11:29:13.370: E/AndroidRuntime(3485): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2085)
01-07 11:29:13.370: E/AndroidRuntime(3485): ... 11 more
答案 0 :(得分:0)
您是否尝试过阅读错误?:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.androidexplorer/com.example.androidexplorer.ReadActivity}; have you declared this activity in your AndroidManifest.xml?
这可能意味着你没有在AndroidManifest中定义你的活动。正确定义它,你应该摆脱那个错误。
答案 1 :(得分:0)
从您的错误中
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.androidexplorer/com.example.androidexplorer.ReadActivity}; have you declared this activity in your AndroidManifest.xml?
显示您尚未在清单文件中声明ReadActivity
活动。
<activity
android:name="com.example.androidexplorer.ReadActivity"
/ >
<强>编辑:强>
SaveString saveStr;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.read);
saveStr = new SaveString();