2015-11-21 1 views
-3

У меня проблема в следующей строкеAndroid-студия «)» ожидается

.setPositiveButton(context.getString(R.string.error_ok_btn_text); 

Вот мой код:

package com.purplesmile.vremenskaprognozasrbija; 

import android.app.AlertDialog; 
import android.app.Dialog; 
import android.app.DialogFragment; 
import android.content.Context; 
import android.os.Bundle; 

public class AlertDialogFragment extends DialogFragment { 

    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     Context context = getActivity(); 
     AlertDialog.Builder builder = new AlertDialog.Builder(context) 
       .setTitle(context.getString(R.string.error_t)) 
       .setMessage(context.getString(R.string.error_massages)) 
       .setPositiveButton(context.getString(R.string.error_ok_btn_text); 

     AlertDialog dialog = builder.create(); 
     return dialog; 
    } 
} 
+7

опечатка: 'setPositiveButton' имеет недостающее закрытие') '- закрытие ... – Reimeus

+0

@Dragi Dragi: Я обновил свой ответ. – Mykola

ответ

4

Этот код, кажется, работает для меня. Не могли бы вы попробовать, если это поможет?

import android.app.AlertDialog; 
import android.app.Dialog; 
import android.app.DialogFragment; 
import android.content.Context; 
import android.content.DialogInterface; 
import android.os.Bundle; 

public class AlertDialogFragment extends DialogFragment { 

    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     Context context = getActivity(); 
     AlertDialog.Builder builder = new AlertDialog.Builder(context) 
      .setTitle(context.getString(R.string.error_t)) 
      .setTitle(context.getString(R.string.error_t)) 
      .setMessage(context.getString(R.string.error_massages)) 
      .setPositiveButton(
        context.getString(R.string.error_ok_btn_text), 
        new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, 
           int which) { 
         } 
        }); 
     AlertDialog dialog = builder.create(); 
     return dialog; 
    } 
} 
+0

Я уже пытаюсь это сделать, и получить ошибку «не могу разрешить метод» «setPositiveButton (java.lang.String)» –

+0

Извините. Я просто получу еще 5 ошибок –

+0

Вышеприведенный код отлично подходит для меня. Не могли бы вы рассказать об ошибках? – Suhas

3

Закройте скобки, как показано ниже:

Изменить

.setPositiveButton(context.getString(R.string.error_ok_btn_text); 

в

.setPositiveButton(context.getString(R.string.error_ok_btn_text)); 
1

Вы просто забыли добавить дополнительные ) выражению.

.setPositiveButton(context.getString(R.string.error_ok_btn_text); 

должен быть

.setPositiveButton(context.getString(R.string.error_ok_btn_text)); 

В документации сказано, следует также указать OnClickButtonListener для этого метода.

декларация

public AlertDialog.Builder setPositiveButton (CharSequence text, DialogInterface.OnClickListener listener) 

примера

.setPositiveButton(context.getString(R.string.error_ok_btn_text), new OnClickListener(){ 
     public void onClick(DialogInterface dialog,int which) { 
     // TO DO: Paste the code wich will execute when the positive button pressed 
    } 
}); 
+0

@ Драги Драги: Я обновил свой ответ. – Mykola

1

Надеется, что вы используете в качестве студии IDE (если не двигаться в Android Studio сразу). Если да, попробуйте использовать функцию автозаполнения, доступную в ней, чтобы избежать таких простых ошибок. См. http://developer.android.com/tools/studio/index.html и http://developer.android.com/tools/studio/index.html

Смежные вопросы