2012-12-11 196 views
0

其中一位下載我的應用的人發現我通過谷歌播放崩潰。我發現它伴隨着車禍和車禍。但我不知道它有什麼問題。對我來說,它總是有效,所以我不知道問題在這裏。這是logcat的:java.lang.RuntimeException:無法啓動活動

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.laurenswuyts.find.it/com.laurenswuyts.find.it.MainKeyboard}: java.lang.NullPointerException 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
at android.app.ActivityThread.access$600(ActivityThread.java:130) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4745) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NullPointerException 
at java.util.Arrays$ArrayList.<init>(Arrays.java:38) 
at java.util.Arrays.asList(Arrays.java:154) 
at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:128) 
at com.laurenswuyts.find.it.MainKeyboard.onCreate(MainKeyboard.java:102) 
at android.app.Activity.performCreate(Activity.java:5008) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
... 11 more 

這是我的代碼:

package com.laurenswuyts.find.it; 

import java.util.Locale; 

import com.laurenswuyts.find.it.R; 

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.KeyEvent; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.Window; 
import android.view.inputmethod.EditorInfo; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.ArrayAdapter; 
import android.widget.AutoCompleteTextView; 
import android.widget.ImageButton; 
import android.widget.TextView; 

public class MainKeyboard extends Activity { 
public String[] taal; 
String[] StringDA = Languages.StringDA; 
String[] StringDE = Languages.StringDE; 
String[] StringFR = Languages2.StringFR; 
String[] StringNL = Languages.StringNL; 
String[] StringEN = Languages.StringEN; 
String[] StringPT = Languages2.StringPT; 
String[] StringSV = Languages.StringSV; 
String[] StringES = Languages2.StringES; 
String[] StringNO = Languages2.StringNO; 

public ImageButton Search; 

public AutoCompleteTextView AutoCompleteTextView; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.mainkeyboard); 





     Search = (ImageButton) findViewById(R.id.imageButtonSearch);   

     final AutoCompleteTextView AutoCompleteTextView = (AutoCompleteTextView) 
       findViewById(R.id.autoCompleteTextView1); 
     if (Locale.getDefault().getLanguage().equals("da")) { 
      taal = StringDA; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("de")) { 
      taal = StringDE; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("fr")) { 
      taal = StringFR; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("nl")) { 
      taal = StringNL; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("no")) { 
      taal = StringNO; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("pt")) { 
      taal = StringPT; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("es")) { 
      taal = StringES; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("sv")) { 
      taal = StringSV; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("en")) { 
      taal = StringEN; 
     } 
     else{ 

     } 

     Search.setOnClickListener(new View.OnClickListener() { 
       public void onClick(View v) { 
        Intent intent = new Intent(MainKeyboard.this,MainActivity.class); 
       intent.putExtra("thetext",AutoCompleteTextView.getText().toString()); 
       startActivity(intent); 
       } 
      }); 

     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.suggest, taal); 

     AutoCompleteTextView acTextView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1); 
     acTextView.setThreshold(1); 
     acTextView.setAdapter(adapter); 
     acTextView.setOnItemClickListener(new OnItemClickListener() { 
      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { 
       Intent intent = new Intent(MainKeyboard.this,MainActivity.class); 
       intent.putExtra("thetext",AutoCompleteTextView.getText().toString()); 
       startActivity(intent); 
      } 
     }); 
       AutoCompleteTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
         public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
          if (actionId == EditorInfo.IME_ACTION_SEARCH) { 
           Intent intent = new Intent(MainKeyboard.this,MainActivity.class); 
           intent.putExtra("thetext",AutoCompleteTextView.getText().toString()); 
           startActivity(intent); 
           return true; 
          } 
          return false; 
         } 
        }); 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
     case R.id.twitter:  Uri uri = Uri.parse("http://twitter.com/finditwurens"); 
     Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
     startActivity(intent); 
     break; 
     case R.id.facebook:  Uri uri2 = Uri.parse("http://www.facebook.com/AppFindIt"); 
     Intent intent2 = new Intent(Intent.ACTION_VIEW, uri2); 
     startActivity(intent2); 
     break; 
     case R.id.googleplus: Uri uri3 = Uri.parse("http://plus.google.com/105389501412708876212/posts"); 
     Intent intent3 = new Intent(Intent.ACTION_VIEW, uri3); 
     startActivity(intent3); 
     break; 
     case R.id.addgoogle: Uri uri4 = Uri.parse("http://www.google.com/places/"); 
     Intent intent4 = new Intent(Intent.ACTION_VIEW, uri4); 
     startActivity(intent4);  
     break; 
     } 
     return true; 
    } 


      } 
+0

什麼是上線102? – Ahmad

+0

你在第102行有一個NullpointerException – Frederic

回答

2

看來你String[] taal;null;(沒有的的if/else可以得到滿足,打印,看看你的設備是哪種語言在通過登錄Locale.getDefault().getLanguage(),這可能給一些線索,爲什麼沒有一個的if/else滿意)

由時間控制達到

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.suggest, taal); 

這導致java.lang.NullPointerException

確保taal不爲空

0

問題是設備的語言不是白色的,你正在考慮的。

嘗試初始化變量taal變量爲默認語言String []。這一個

if (Locale.getDefault().getLanguage().equals("en")) { 
    taal = StringEN; 
} 
else{ 
} 

1

將以下代碼

if (taal == null) { 
    taal = StringEN; 
} 

這樣,英語被設置爲默認語言,如果你不支持用戶的特定語言。

0

-你有卻從未初始化數組public String[] taal;

-其次我想請您使用ArrayList<String>而不是Array,爲CollectionsArrays靈活得多。

1

你的條件都不是真的,我會建議你設置一個默認的語言在你else語句:

if (Locale.getDefault().getLanguage().equals("da")) { 
      taal = StringDA; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("de")) { 
      taal = StringDE; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("fr")) { 
      taal = StringFR; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("nl")) { 
      taal = StringNL; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("no")) { 
      taal = StringNO; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("pt")) { 
      taal = StringPT; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("es")) { 
      taal = StringES; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("sv")) { 
      taal = StringSV; 
     } 
     else{} 
     if (Locale.getDefault().getLanguage().equals("en")) { 
      taal = StringEN; 
     } 
     else{ 
      taal = StringEN; //or whatever default language 
     } 
相關問題