如何解决"无法到达的声明"

时间:2015-04-14 16:17:44

标签: java android

这是我的Android代码。我在下面的行Toast中出现错误,说“无法访问的语句”,我知道此错误来自return If但我不知道如何解决它

错误部分:

do
{
    return;
    if ((paramAnonymous2Int == 0) && (AndroidHTMLActivity.this.Count == 4))
    {
        Toast.makeText(getApplicationContext(),"نسخه رایگان",Toast.LENGTH_SHORT).show();
        return;
    }
}

整个功能:

@JavascriptInterface
    public void SaveDialog(final String paramString)
    {
        final SQLiteDatabase mydatabase = openOrCreateDatabase("CopyCollection", MODE_PRIVATE, null);
        Object localObject = mydatabase.rawQuery("SELECT * FROM Details WHERE ID=" + paramString + ";", null);
        if (((Cursor)localObject).moveToFirst()) {
            do
            {
                AndroidHTMLActivity.this.appName = ((Cursor)localObject).getString(1);
                AndroidHTMLActivity.this.txtClip = ((Cursor)localObject).getString(2);
                AndroidHTMLActivity.this.text_Date = ((Cursor)localObject).getString(3);
            } while (((Cursor)localObject).moveToNext());
        }
        localObject = new AlertDialog.Builder(AndroidHTMLActivity.this);
        ((AlertDialog.Builder)localObject).setTitle("ذخیره");
        ((AlertDialog.Builder)localObject).setPositiveButton("ذخیره", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
            {
                final SQLiteDatabase mydatabase1 = openOrCreateDatabase("CopyCollection", MODE_PRIVATE, null);
                Cursor crs = mydatabase1.rawQuery("SELECT * FROM Groups;",null);
                String[] array = new String[crs.getCount()];
                int[] arrayID = new int[crs.getCount()];
                Count = crs.getCount();
                int i = 0;
                while(crs.moveToNext()){
                    String uname = crs.getString(crs.getColumnIndex("GroupName"));
                    int id = crs.getColumnIndex("ID");
                    arrayID[i] = id;
                    array[i] = uname;
                    i++;
                }
                final AlertDialog.Builder builder = new AlertDialog.Builder(AndroidHTMLActivity.this);
                builder.setTitle("گروه خود را انتخاب کنید");
                builder.setItems(paramAnonymousDialogInterface, new DialogInterface.OnClickListener()
                {
                    public void onClick(final DialogInterface paramAnonymous2DialogInterface, int paramAnonymous2Int)
                    {
                        strI = String.valueOf(paramAnonymous2Int);
                        String localObject1 = String.valueOf(paramAnonymous2Int);
                        final SQLiteDatabase mydatabase = openOrCreateDatabase("CopyCollection", MODE_PRIVATE, null);
                        Cursor localObject2 = mydatabase.rawQuery("SELECT * FROM Status WHERE ID=1;", null);
                        if ((localObject2).moveToFirst()) {
                            do
                            {
                                AndroidHTMLActivity.this.Trial = (localObject2).getInt(1);
                            } while ((localObject2).moveToNext());
                        }
                        if ((paramAnonymous2Int == 0) && (AndroidHTMLActivity.this.Count != 4))
                        {
                            final AlertDialog.Builder builder1 = new AlertDialog.Builder(AndroidHTMLActivity.this);
                            builder1.setTitle("درج عنوان گروه");
                            final EditText input = new EditText(AndroidHTMLActivity.this);
                            input.setInputType(1);
                            builder1.setView(input);
                            builder1.setPositiveButton("تایید", new DialogInterface.OnClickListener()
                            {
                                public void onClick(DialogInterface paramAnonymous3DialogInterface, int paramAnonymous3Int)
                                {
                                    m_Text = input.getText().toString();
                                    mydatabase.execSQL("INSERT INTO Groups (GroupName) VALUES('" + m_Text + "');");
                                    Cursor c3 = mydatabase.rawQuery("SELECT * FROM Groups ORDER BY ID DESC LIMIT 1;", null);
                                    if ((c3 != null) && (c3.moveToFirst()))
                                    {
                                        long l = c3.getLong(0);
                                        LastDir = String.valueOf(l);
                                    }
                                    mydatabase.execSQL("INSERT INTO MainContent(AppName,Txt,GroupID,Time)VALUES('" + appName + "','" + txtClip + "','" + LastDir + "','" + text_Date + "');");
                                    mydatabase.execSQL("DELETE FROM Details WHERE ID = " + paramString + ";");
                                    mydatabase.close();
                                }
                            });
                            builder1.setNegativeButton("انصراف", new DialogInterface.OnClickListener()
                            {
                                public void onClick(DialogInterface paramAnonymous3DialogInterface, int paramAnonymous3Int)
                                {
                                    paramAnonymous3DialogInterface.cancel();
                                    AndroidHTMLActivity.this.myBrowser.post(new Runnable()
                                    {
                                        public void run()
                                        {
                                            myBrowser.loadUrl("javascript:fill_comment()");
                                        }
                                    });
                                }
                            });
                            builder1.show();
                        }
                        do
                        {
                            return;
                            if ((paramAnonymous2Int == 0) && (AndroidHTMLActivity.this.Count == 4))
                            {
                                Toast.makeText(getApplicationContext(),"نسخه رایگان",Toast.LENGTH_SHORT).show();
                                return;
                            }
                        }
                        while (paramAnonymous2Int == 0);
                        Cursor c2 = mydatabase.rawQuery("SELECT count(*) FROM `MainContent` WHERE `GroupID` LIKE '" + localObject1 + "'", null);
                        (c2).moveToFirst();
                        if ((c2).getInt(0) < 5)
                        {
                            mydatabase.execSQL("INSERT INTO MainContent (AppName,Txt,GroupID,Time) VALUES('" + AndroidHTMLActivity.this.appName + "','" + AndroidHTMLActivity.this.txtClip + "','" + (String)localObject1 + "','" + text_Date + "');");
                            mydatabase.execSQL("DELETE FROM Details WHERE ID = " + paramString + ";");
                            mydatabase.close();
                        }
                        Toast.makeText(getApplicationContext(),"نسخه رایگان",Toast.LENGTH_SHORT).show();
                        AndroidHTMLActivity.this.myBrowser.post(new Runnable()
                        {
                            public void run()
                            {
                                AndroidHTMLActivity.this.myBrowser.loadUrl("javascript:fill_comment()");
                            }
                        });
                    }
                });
                builder.create().show();
            }
        });
        ((AlertDialog.Builder)localObject).setNegativeButton("اشتراک گذاری", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
            {
                Intent intent = new Intent("android.intent.action.SEND");
                intent.setType("text/plain");
                String str = txtClip;
                intent.putExtra("android.intent.extra.SUBJECT", "Subject");
                intent.putExtra("android.intent.extra.TEXT", str);
                startActivity(Intent.createChooser(intent, "Share via"));
            }
        });
        ((AlertDialog.Builder)localObject).show();
    }

    @JavascriptInterface
    public void configuration()
    {
        Intent localIntent = new Intent(AndroidHTMLActivity.this, Directory.class);
        AndroidHTMLActivity.this.startActivity(localIntent);
        AndroidHTMLActivity.this.finish();
    }

4 个答案:

答案 0 :(得分:2)

看看这段代码

return;
if ((paramAnonymous2Int == 0) && (AndroidHTMLActivity.this.Count == 4))

您在验证之前返回,因此永远不会到达它。

答案 1 :(得分:1)

return块的开头简单删除do语句。

return表示立即退出,因此在该行之后没有其他代码。

答案 2 :(得分:0)

将您的行为改为此

    do
    {
    if ((paramAnonymous2Int == 0) && (AndroidHTMLActivity.this.Count == 4))
    {
        Toast.makeText(getApplicationContext(),"نسخه رایگان",Toast.LENGTH_SHORT).show();
        return;
    }
}

它永远不会到达,因为你在Do

的开头回来了

答案 3 :(得分:0)

在java遇到return时,它只退出该方法。执行返回后,其余代码将无法执行。 Java编译器检测到无法访问的代码,它将给出错误。

if(condition)
{
    return;
    yougetunreachableerror();//compiler gives error
}