0

私はAndroidの初心者です。ユーザーが入力した URL に依存するアプリを作成しています。メイン アクティビティに、ユーザー設定が設定されているかどうかを検出するコードがあります。そうでない場合は、編集設定アクティビティが開きます。

ただし、新しい優先設定を「登録」する前に、アプリが少なくとも 1 回か 2 回クラッシュする必要があります。どうすればこれを修正できますか?

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

    // integrate our shared preferences settings
    sharedPrefs = PreferenceManager
            .getDefaultSharedPreferences(this);
    prefix = sharedPrefs.getString("manual_fetch_domain", "");

    if (prefix.length() < 7) {
        startActivity(new Intent(this, EditSettingsActivity.class));
    }
}

public void onPrimaryClick(View view) {
    Intent intent = new Intent(getApplicationContext(),
            PrimaryImageGridActivity.class);

    //confirm our settings
    if (prefix.length() < 7) {
        startActivity(new Intent(this, EditSettingsActivity.class));
    }

    String readTwitterFeed = readTwitterFeed(prefix + Constants.SERVER_URL);
    List<String> where = new ArrayList<String>();
    int k = 0;

    if (readTwitterFeed != null) {
        //code here
    }

}

public String readTwitterFeed(String y) {
    StringBuilder builder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(y);
    try {
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(content), 16384);
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // error check again
    String tmp = builder.toString();
    if (tmp.length() < 2)
        return null;
    else
        return builder.toString();
}

私の丸太猫のセクションは次のとおりです。

07-10 13:23:18.818: E/AndroidRuntime(767): FATAL EXCEPTION: main
07-10 13:23:18.818: E/AndroidRuntime(767): java.lang.IllegalStateException: Could not execute method of the activity
07-10 13:23:18.818: E/AndroidRuntime(767):  at android.view.View$1.onClick(View.java:3599)
07-10 13:23:18.818: E/AndroidRuntime(767):  at android.view.View.performClick(View.java:4204)
07-10 13:23:18.818: E/AndroidRuntime(767):  at android.view.View$PerformClick.run(View.java:17355)
07-10 13:23:18.818: E/AndroidRuntime(767):  at android.os.Handler.handleCallback(Handler.java:725)
07-10 13:23:18.818: E/AndroidRuntime(767):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-10 13:23:18.818: E/AndroidRuntime(767):  at android.os.Looper.loop(Looper.java:137)
07-10 13:23:18.818: E/AndroidRuntime(767):  at android.app.ActivityThread.main(ActivityThread.java:5041)
07-10 13:23:18.818: E/AndroidRuntime(767):  at java.lang.reflect.Method.invokeNative(Native Method)
07-10 13:23:18.818: E/AndroidRuntime(767):  at java.lang.reflect.Method.invoke(Method.java:511)
07-10 13:23:18.818: E/AndroidRuntime(767):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-10 13:23:18.818: E/AndroidRuntime(767):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-10 13:23:18.818: E/AndroidRuntime(767):  at dalvik.system.NativeStart.main(Native Method)
07-10 13:23:18.818: E/AndroidRuntime(767): Caused by: java.lang.reflect.InvocationTargetException
07-10 13:23:18.818: E/AndroidRuntime(767):  at java.lang.reflect.Method.invokeNative(Native Method)
07-10 13:23:18.818: E/AndroidRuntime(767):  at java.lang.reflect.Method.invoke(Method.java:511)
07-10 13:23:18.818: E/AndroidRuntime(767):  at android.view.View$1.onClick(View.java:3594)
07-10 13:23:18.818: E/AndroidRuntime(767):  ... 11 more
07-10 13:23:18.818: E/AndroidRuntime(767): Caused by: java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=/
07-10 13:23:18.818: E/AndroidRuntime(767):  at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:591)
07-10 13:23:18.818: E/AndroidRuntime(767):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:293)
07-10 13:23:18.818: E/AndroidRuntime(767):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-10 13:23:18.818: E/AndroidRuntime(767):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-10 13:23:18.818: E/AndroidRuntime(767):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-10 13:23:18.818: E/AndroidRuntime(767):  at com.src.shady.MainActivity.readTwitterFeed(MainActivity.java:118)
07-10 13:23:18.818: E/AndroidRuntime(767):  at com.src.shady.MainActivity.onPrimaryImageGridClick(MainActivity.java:67)
4

1 に答える 1