我有一个 ListView,所以我在 main.xml 设计器中删除了它,它也自动从 main.xml 代码中删除。
然后我向设计器添加了一个微调器,它也自动添加到 main.xml 代码中。在我的程序中,我删除了 ListView 的所有用途并使用微调器添加。
然后我在一行上进行了调试,当我在调试模式下运行我的应用程序并选择是时,我在调试窗口中收到一个红色的错误消息Source not found
。
我有一个可以点击的按钮:Edit a source lookup path
我不确定问题出在哪里以及如何解决。5 分钟前,在我删除 ListView 并在设计器中添加微调器之前,它运行良好。
这是 main.xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/btnSpeak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<EditText
android:id="@+id/txtText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
这是我的java类代码:
package com.testotspeech;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class AndroidTestToSpeechActivity extends Activity implements
TextToSpeech.OnInitListener {
/** Called when the activity is first created. */
private TextToSpeech tts;
private Button btnSpeak;
private EditText txtText;
private String array_spinner[];
private ArrayList<String> itemsList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("----------",Arrays.toString(Locale.getAvailableLocales()));
itemsList.add(Arrays.toString(Locale.getAvailableLocales()));
array_spinner = new String[itemsList.size()];
tts = new TextToSpeech(this, this);
btnSpeak = (Button) findViewById(R.id.btnSpeak);
txtText = (EditText) findViewById(R.id.txtText);
// button on click event
btnSpeak.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
speakOut();
}
});
}
@Override
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.ENGLISH);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
btnSpeak.setEnabled(true);
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
private void speakOut() {
String text = txtText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
什么可能导致错误?
谢谢。
编辑:这是堆栈跟踪日志,只有红色错误:
06-04 20:20:05.609: E/AndroidRuntime(8567): FATAL EXCEPTION: main
06-04 20:20:05.609: E/AndroidRuntime(8567): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testotspeech/com.testotspeech.AndroidTestToSpeechActivity}: java.lang.NullPointerException
06-04 20:20:05.609: E/AndroidRuntime(8567): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
06-04 20:20:05.609: E/AndroidRuntime(8567): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
06-04 20:20:05.609: E/AndroidRuntime(8567): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
06-04 20:20:05.609: E/AndroidRuntime(8567): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
06-04 20:20:05.609: E/AndroidRuntime(8567): at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 20:20:05.609: E/AndroidRuntime(8567): at android.os.Looper.loop(Looper.java:144)
06-04 20:20:05.609: E/AndroidRuntime(8567): at android.app.ActivityThread.main(ActivityThread.java:4937)
06-04 20:20:05.609: E/AndroidRuntime(8567): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 20:20:05.609: E/AndroidRuntime(8567): at java.lang.reflect.Method.invoke(Method.java:521)
06-04 20:20:05.609: E/AndroidRuntime(8567): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-04 20:20:05.609: E/AndroidRuntime(8567): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-04 20:20:05.609: E/AndroidRuntime(8567): at dalvik.system.NativeStart.main(Native Method)
06-04 20:20:05.609: E/AndroidRuntime(8567): Caused by: java.lang.NullPointerException
06-04 20:20:05.609: E/AndroidRuntime(8567): at com.testotspeech.AndroidTestToSpeechActivity.onCreate(AndroidTestToSpeechActivity.java:30)
06-04 20:20:05.609: E/AndroidRuntime(8567): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
06-04 20:20:05.609: E/AndroidRuntime(8567): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
06-04 20:20:05.609: E/AndroidRuntime(8567): ... 11 more
06-04 20:22:54.219: E/ActivityManager(127): fail to set top app changed!
06-04 20:24:32.509: E/ActivityManager(127): fail to set top app changed!
06-04 20:25:45.439: E/ActivityManager(127): fail to set top app changed!
06-04 20:32:49.439: E/ActivityManager(127): fail to set top app changed!
06-04 20:33:06.109: E/lights(127): write ok string=0,len=1
06-04 20:33:06.109: E/lights(127): write ok string=0,len=1
06-04 20:33:06.119: E/lights(127): write ok string=0 0,len=3
06-04 20:33:06.119: E/lights(127): write ok string=1,len=1
06-04 20:33:06.129: E/lights(127): write ok string=0,len=1
06-04 20:33:06.129: E/lights(127): write ok string=0 0,len=3
06-04 20:33:06.149: E/lights(127): write ok string=0,len=1
06-04 20:33:06.159: E/lights(127): write ok string=0,len=1
06-04 20:33:06.159: E/lights(127): write ok string=0 0,len=3
06-04 20:33:06.169: E/lights(127): write ok string=1,len=1
06-04 20:33:06.169: E/lights(127): write ok string=0,len=1
06-04 20:33:06.169: E/lights(127): write ok string=0 0,len=3
06-04 20:33:09.179: E/lights(127): write ok string=0,len=1
06-04 20:33:09.179: E/lights(127): write ok string=0,len=1
06-04 20:33:09.179: E/lights(127): write ok string=0 0,len=3
06-04 20:33:09.189: E/lights(127): write ok string=1,len=1
06-04 20:33:09.189: E/lights(127): write ok string=0,len=1
06-04 20:33:09.189: E/lights(127): write ok string=0 0,len=3
06-04 20:33:16.309: E/AndroidRuntime(8748): FATAL EXCEPTION: main
06-04 20:33:16.309: E/AndroidRuntime(8748): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testotspeech/com.testotspeech.AndroidTestToSpeechActivity}: java.lang.NullPointerException
06-04 20:33:16.309: E/AndroidRuntime(8748): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
06-04 20:33:16.309: E/AndroidRuntime(8748): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
06-04 20:33:16.309: E/AndroidRuntime(8748): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
06-04 20:33:16.309: E/AndroidRuntime(8748): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
06-04 20:33:16.309: E/AndroidRuntime(8748): at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 20:33:16.309: E/AndroidRuntime(8748): at android.os.Looper.loop(Looper.java:144)
06-04 20:33:16.309: E/AndroidRuntime(8748): at android.app.ActivityThread.main(ActivityThread.java:4937)
06-04 20:33:16.309: E/AndroidRuntime(8748): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 20:33:16.309: E/AndroidRuntime(8748): at java.lang.reflect.Method.invoke(Method.java:521)
06-04 20:33:16.309: E/AndroidRuntime(8748): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-04 20:33:16.309: E/AndroidRuntime(8748): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-04 20:33:16.309: E/AndroidRuntime(8748): at dalvik.system.NativeStart.main(Native Method)
06-04 20:33:16.309: E/AndroidRuntime(8748): Caused by: java.lang.NullPointerException
06-04 20:33:16.309: E/AndroidRuntime(8748): at com.testotspeech.AndroidTestToSpeechActivity.onCreate(AndroidTestToSpeechActivity.java:30)
06-04 20:33:16.309: E/AndroidRuntime(8748): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
06-04 20:33:16.309: E/AndroidRuntime(8748): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
06-04 20:33:16.309: E/AndroidRuntime(8748): ... 11 more
06-04 20:33:16.339: E/lights(127): write ok string=0,len=1
06-04 20:33:16.349: E/lights(127): write ok string=0,len=1
06-04 20:33:16.349: E/lights(127): write ok string=0 0,len=3
06-04 20:33:16.349: E/lights(127): write ok string=1,len=1
06-04 20:33:16.349: E/lights(127): write ok string=0,len=1
06-04 20:33:16.359: E/lights(127): write ok string=0 0,len=3
06-04 20:33:16.559: E/lights(127): write ok string=0,len=1
06-04 20:33:16.569: E/lights(127): write ok string=0,len=1
06-04 20:33:16.579: E/lights(127): write ok string=0 0,len=3
06-04 20:33:16.579: E/lights(127): write ok string=0,len=1
06-04 20:33:16.579: E/lights(127): write ok string=0,len=1
06-04 20:33:16.579: E/lights(127): write ok string=0 0,len=3
06-04 20:33:16.629: E/lights(127): write ok string=0,len=1
06-04 20:33:16.639: E/lights(127): write ok string=0,len=1
06-04 20:33:16.639: E/lights(127): write ok string=0 0,len=3
06-04 20:33:16.639: E/lights(127): write ok string=0,len=1
06-04 20:33:16.639: E/lights(127): write ok string=0,len=1
06-04 20:33:16.649: E/lights(127): write ok string=0 0,len=3
06-04 20:33:18.789: E/lights(127): write ok string=0,len=1
06-04 20:33:18.789: E/lights(127): write ok string=0,len=1
06-04 20:33:18.789: E/lights(127): write ok string=0 0,len=3
06-04 20:33:18.789: E/lights(127): write ok string=0,len=1
06-04 20:33:18.799: E/lights(127): write ok string=0,len=1
06-04 20:33:18.799: E/lights(127): write ok string=0 0,len=3
06-04 20:33:23.009: E/lights(127): write ok string=0,len=1
06-04 20:33:23.019: E/lights(127): write ok string=0,len=1
06-04 20:33:23.019: E/lights(127): write ok string=0 0,len=3
06-04 20:33:23.019: E/lights(127): write ok string=1,len=1
06-04 20:33:23.029: E/lights(127): write ok string=0,len=1
06-04 20:33:23.029: E/lights(127): write ok string=0 0,len=3
06-04 20:33:23.049: E/DatabaseUtils(367): Writing exception to parcel
06-04 20:33:23.049: E/DatabaseUtils(367): java.lang.SecurityException: Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/download from pid=316, uid=10007 requires android.permission.ACCESS_DOWNLOAD_MANAGER
06-04 20:33:23.049: E/DatabaseUtils(367): at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:277)
06-04 20:33:23.049: E/DatabaseUtils(367): at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:155)
06-04 20:33:23.049: E/DatabaseUtils(367): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:134)
06-04 20:33:23.049: E/DatabaseUtils(367): at android.os.Binder.execTransact(Binder.java:288)
06-04 20:33:23.049: E/DatabaseUtils(367): at dalvik.system.NativeStart.run(Native Method)
06-04 20:33:23.049: E/SwitchUsbSettings(316): Error when query download provider. error: java.lang.SecurityException: Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/download from pid=316, uid=10007 requires android.permission.ACCESS_DOWNLOAD_MANAGER
06-04 20:33:23.149: E/DatabaseUtils(367): Writing exception to parcel
06-04 20:33:23.149: E/DatabaseUtils(367): java.lang.SecurityException: Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/download from pid=316, uid=10007 requires android.permission.ACCESS_DOWNLOAD_MANAGER
06-04 20:33:23.149: E/DatabaseUtils(367): at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:277)
06-04 20:33:23.149: E/DatabaseUtils(367): at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:155)
06-04 20:33:23.149: E/DatabaseUtils(367): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:134)
06-04 20:33:23.149: E/DatabaseUtils(367): at android.os.Binder.execTransact(Binder.java:288)
06-04 20:33:23.149: E/DatabaseUtils(367): at dalvik.system.NativeStart.run(Native Method)
06-04 20:33:23.149: E/SwitchUsbSettings(316): Error when query download provider. error: java.lang.SecurityException: Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/download from pid=316, uid=10007 requires android.permission.ACCESS_DOWNLOAD_MANAGER
06-04 20:33:56.369: E/ActivityManager(127): fail to set top app changed!
06-04 20:38:30.539: E/ActivityManager(127): fail to set top app changed!
06-04 20:50:48.819: E/ActivityManager(127): fail to set top app changed!
06-04 20:51:59.019: E/ActivityManager(127): fail to set top app changed!
06-04 23:01:32.909: E/Tethering(127): active iface (usb0) reported as added, ignoring
06-04 23:02:23.029: E/Tethering(127): active iface (usb0) reported as added, ignoring
06-04 23:04:03.339: E/Tethering(127): active iface (usb0) reported as added, ignoring
06-04 23:07:23.899: E/Tethering(127): active iface (usb0) reported as added, ignoring
06-04 23:09:54.619: E/Tethering(127): active iface (usb0) reported as added, ignoring
06-04 23:14:04.959: E/Tethering(127): active iface (usb0) reported as added, ignoring
06-04 23:16:35.439: E/Tethering(127): active iface (usb0) reported as added, ignoring
06-04 23:20:58.319: E/jdwp(9122): Failed sending reply to debugger: Broken pipe
06-04 23:21:36.259: E/Tethering(127): active iface (usb0) reported as added, ignoring