我的Android应用程序在galaxy选项卡中崩溃,但在Android 4.0的所有移动设备中都正常工作。以下是我从Play商店的崩溃报告中复制的错误:
java.lang.NullPointerException
at kids.iq.kidsiqpicturesquestionfull.vocabulary_animal.speakWords(vocabulary_animal.java:74)
at kids.iq.kidsiqpicturesquestionfull.vocabulary_animal.access$0(vocabulary_animal.java:72)
at kids.iq.kidsiqpicturesquestionfull.vocabulary_animal$1.onItemClick(vocabulary_animal.java:66)
at android.widget.AdapterView.performItemClick(AdapterView.java:315)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1852)
at android.os.Handler.handleCallback(Handler.java:618)
at android.os.Handler.dispatchMessage(Handler.java:123)
at android.os.Looper.loop(SourceFile:351)
at android.app.ActivityThread.main(ActivityThread.java:3814)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:538)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:659)
at dalvik.system.NativeStart.main(Native Method)
package kids.iq.kidsiqpicturesquestionfull;
import java.util.Locale;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import com.google.analytics.tracking.android.EasyTracker;
public class vocabulary_animal extends Activity implements OnClickListener, OnInitListener{
private AdView adView;
private int MY_DATA_CHECK_CODE = 0;
private TextToSpeech tts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.vocabulary_animal);
adView = new AdView(this, AdSize.BANNER, "96ffc9a995384d59");
AdView ad = (AdView) findViewById(R.id.adsView);
ad.loadAd(new AdRequest());
//check for TTS data
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/TRIFORCE.ttf");
TextView text_title = (TextView) findViewById(R.id.text_title);
text_title.setTypeface(typeFace);
GridView gridview = (GridView) findViewById(R.id.animal_gridview);
gridview.setAdapter(new Vocabulary_Gride_Adapter_Animal(this));
final Vocabulary_Gride_Adapter_Animal imageAdapter = new Vocabulary_Gride_Adapter_Animal(this);
gridview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
String name = getResources().getResourceEntryName(imageAdapter.mThumbIds[position]);
String me = Character.toUpperCase(name.charAt(0)) + name.substring(1);
speakWords(name);
Toast.makeText(vocabulary_animal.this, "" + me, Toast.LENGTH_SHORT).show();
}
});
}
private void speakWords(String speech) {
//speak straight away
tts.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
//the user has the necessary data - create the TTS
tts = new TextToSpeech(this, this);
}
else {
//no data - install it now
Intent installTTSIntent = new Intent();
installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installTTSIntent);
}
}
}
//setup TTS
@Override
public void onInit(int initStatus) {
//check for successful instantiation
if (initStatus == TextToSpeech.SUCCESS) {
if(tts.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE)
tts.setLanguage(Locale.US);
tts.setLanguage(Locale.US);
tts.setPitch((float) 1);
tts.setSpeechRate(1);
}
else if (initStatus == TextToSpeech.ERROR) {
Toast.makeText(this, "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show();
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
@Override
public void onDestroy()
{
adView.destroy();
super.onDestroy();
}
@Override
public void onStart()
{
super.onStart();
EasyTracker.getInstance().activityStart(this);
}
@Override
public void onStop()
{
super.onStop();
EasyTracker.getInstance().activityStop(this);
}
}
这里我的游戏link在游戏商店中,它与每部手机都能正常工作,但是每个与语音相关的活动的所有星系标签都会出现错误。
java.lang.NullPointerException
at kids.iq.kidsiqpicturesquestionfull.fruit_q_easy_1$4.onClick(fruit_q_easy_1.java:655)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
关于非初始化tts字段的第一次崩溃。您已初始化链接使用率。现在只在活动结果
之后才启动它@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
//the user has the necessary data - create the TTS
tts = new TextToSpeech(this, this);
}
这就是为什么你接受了NullPointerException。这不是供应商或设备问题。它唯一的代码。