0

下载我的应用程序的人之一通过谷歌播放向我发送了崩溃。我发现它在崩溃和 anr 内。但我不知道它有什么问题。对我来说它总是有效,所以我不知道这里有什么问题。这是日志:

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;
    }


            }
4

5 回答 5

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不是null

于 2012-12-11T16:40:49.440 回答
1

替换以下代码:

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

有了这个:

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

如果您不支持用户特定的语言,那么英语将被设置为默认语言。

于 2012-12-11T16:44:29.047 回答
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
       }
于 2012-12-11T16:45:47.040 回答
0

问题是设备的语言与您正在考虑的语言不同。

尝试将您的变量初始化taal为默认语言String []

于 2012-12-11T16:43:19.440 回答
0

-实际上从未初始化过 Arraypublic String[] taal;

-其次,我会要求您使用ArrayList<String>而不是Array,因为Collections它比Arrays.

于 2012-12-11T16:45:40.733 回答