Skip to main content
adicionou 1763 caracteres ao conteúdo
Fonte Link
user28595
user28595

Como resolver o problema de cannot find symbol da variavel no android studio?

//função Função de click @Override public void onClick(View v) { switch (v.getId()) { case R.id.imageToUpload: Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE); break;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imageToUpload:
                Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
                break;

            case R.id.bUploadImage:

                break;
            case R.id.bDownloadImage:

                break;
        }
    }

// as bibliotecas usadas import android.graphics.Bitmap.Config; import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.provider.MediaStore; import android.speech.RecognizerIntent; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.widget.DrawerLayout; import android.text.Html; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.JavascriptInterface; import android.webkit.WebView; import android.widget.AdapterView; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; import android.widget.Toast;

import java.util.ArrayList;

//A classe MainActivity

public classClasse MainActivity extends Activity implements View.OnClickListener{

ImageView// imageToUpload,as downloadedImage;bibliotecas usadas
Buttonimport bUploadImage,android.graphics.Bitmap.Config;
import bDownloadImage;android.app.AlertDialog;
EditTextimport uploadImageName,android.content.ActivityNotFoundException;
import downloadImageName;android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.provider.MediaStore;
import android.speech.RecognizerIntent;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.text.Html;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

// declareimport propertiesjava.util.ArrayList;

private static final int SPEECH_REQUEST_CODE = 2;
private String[] mNavigationDrawerItemTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;

private//A ActionBarDrawerToggleclasse mDrawerToggle;MainActivity 

//public navclass drawerMainActivity title
privateextends CharSequenceActivity mDrawerTitle;implements  View.OnClickListener{

WebView myWebView;   ImageView imageToUpload, downloadedImage;
    Button bUploadImage, bDownloadImage;
    EditText uploadImageName, downloadImageName;

// used to store app title
private// CharSequencedeclare mTitle;properties

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    // for proper titles
  private static mTitlefinal =int mDrawerTitleSPEECH_REQUEST_CODE = getTitle();
    
    // initialize properties2;
    mNavigationDrawerItemTitlesprivate =String[] getResources().getStringArray(R.array.navigation_drawer_items_array);mNavigationDrawerItemTitles;
    mDrawerLayout =private (DrawerLayout) findViewById(R.id.drawer_layout);mDrawerLayout;
    mDrawerList =private (ListView) findViewById(R.id.left_drawer);
    
    // list the drawer items
    ObjectDrawerItem[] drawerItem = new ObjectDrawerItem[6];
    
    drawerItem[0] = new ObjectDrawerItem(R.drawable.ic_home, "Home");
    drawerItem[1] = new ObjectDrawerItem(R.drawable.ic_manufacturing, "Manufacturing");
    drawerItem[2] = new ObjectDrawerItem(R.drawable.ic_engineering, "Engineering");
    drawerItem[3] = new ObjectDrawerItem(R.drawable.ic_quality, "Quality");
    drawerItem[4] = new ObjectDrawerItem(R.drawable.ic_orderexecution, "Order Execution");
    drawerItem[5] = new ObjectDrawerItem(R.drawable.ic_exit, "Exit");mDrawerList;

    // Pass the folderData to our ListView adapter
    DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.listview_item_row, drawerItem);
    
    // Set the adapter for the list view
    mDrawerList.setAdapter(adapter);
    
    // set the item click listener
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
  private ActionBarDrawerToggle mDrawerToggle;

    // for app icon control for nav drawer
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);title
    mDrawerToggle =private newCharSequence ActionBarDrawerToggle(mDrawerTitle;
            this,         
    WebView myWebView;
  
    /* host Activity */
            mDrawerLayout,        used /*to DrawerLayoutstore objectapp */title
      private CharSequence mTitle;

    R.drawable.ic_drawer_white,@Override
  /* nav drawer icon toprotected replacevoid 'Up'onCreate(Bundle caretsavedInstanceState) */{
            R.stringsuper.drawer_open,  /* "open drawer" description */onCreate(savedInstanceState);
            setContentView(R.stringlayout.drawer_close  /* "close drawer" description */
            activity_main) {;
        
        // for proper titles
        mTitle = mDrawerTitle = getTitle();
        
        // initialize properties
        mNavigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);
        
        // list the drawer items
        ObjectDrawerItem[] drawerItem = new ObjectDrawerItem[6];
        
        drawerItem[0] = new ObjectDrawerItem(R.drawable.ic_home, "Home");
        drawerItem[1] = new ObjectDrawerItem(R.drawable.ic_manufacturing, "Manufacturing");
        drawerItem[2] = new ObjectDrawerItem(R.drawable.ic_engineering, "Engineering");
        drawerItem[3] = new ObjectDrawerItem(R.drawable.ic_quality, "Quality");
        drawerItem[4] = new ObjectDrawerItem(R.drawable.ic_orderexecution, "Order Execution");
        drawerItem[5] = new ObjectDrawerItem(R.drawable.ic_exit, "Exit");

        // Pass the folderData to our ListView adapter
        DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.listview_item_row, drawerItem);
        
        // Set the adapter for the list view
        mDrawerList.setAdapter(adapter);
        
        // set the item click listener
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
        

        // for app icon control for nav drawer
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerToggle = new ActionBarDrawerToggle(
                this,                  /* host Activity */
                mDrawerLayout,         /* DrawerLayout object */
                R.drawable.ic_drawer_white,  /* nav drawer icon to replace 'Up' caret */
                R.string.drawer_open,  /* "open drawer" description */
                R.string.drawer_close  /* "close drawer" description */
                ) {
            
            /** Called when a drawer has settled in a completely closed state. */
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>"+mTitle+"</font>"));
            }

            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                //getActionBar().setTitle(mDrawerTitle);
                getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>Merweb Mobile</font>"));

            }
        };

        // Set the drawer toggle as the DrawerListener
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        
        // enable ActionBar app icon to behave as action to toggle nav drawer
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);

        if (savedInstanceState == null) {
            // on first time display view for first nav item
            selectItem(0);
        }

        /**/Para Calledfazer wheno aupload drawerde hasimagens
 settled in a completely open state  super.onCreate(savedInstanceState);
 */       setContentView(R.layout.activity_main);

        publicimageToUpload void= onDrawerOpened(View drawerViewImageView) {findViewById(R.id.imageToUpload);
         downloadedImage = (ImageView) super.onDrawerOpenedfindViewById(drawerViewR.id.downloadedImage); 

        bUploadImage = (Button) findViewById(R.id.bUploadImage);
 //getActionBar       bDownloadImage = (Button).setTitle findViewById(mDrawerTitleR.id.bDownloadImage); 

        uploadImageName = (EditText)  getActionBarfindViewById()R.setTitleid.etUploadName);
        downloadImageName = (HtmlEditText) findViewById(R.fromHtmlid.etDownloadName);

        imageToUpload.setOnClickListener("<fontthis);
 color='#ffffff'>Merweb Mobile</font>"      bUploadImage.setOnClickListener(this);
        bDownloadImage.setOnClickListener(this);
    }

    // Create an intent that can start the Speech Recognizer activity
    private void displaySpeechRecognizer() {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        // Start the activity, the intent will be populated with the speech text
        try {
            startActivityForResult(intent, SPEECH_REQUEST_CODE);
        } catch (ActivityNotFoundException a) {
            Toast t = Toast.makeText(getApplicationContext(), "Ops! Your device doesn't support Speech to Text", Toast.LENGTH_SHORT);
            t.show();
        }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);}
    
    // enableAqui ActionBarestamos apppegando icono tocodigo behavede asBarras
 action to toggle navpublic drawervoid onActivityResult(int requestCode, int resultCode, Intent intent, Intent data) {
    getActionBar    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent).setDisplayHomeAsUpEnabled;
        Fragment fragment = null;
        FragmentManager fragmentManager = getFragmentManager(true);
//    getActionBar    Toast t = Toast.makeText(getApplicationContext(), requestCode + " " + resultCode, Toast.setHomeButtonEnabledLENGTH_SHORT);
//        t.show(true);
        if (requestCode == 49374) {
            if (scanResult != null) {

                String re = scanResult.getContents();

                if (savedInstanceStatere == null) {
                    fragmentManager.beginTransaction().replace(R.id.content_frame, new HomeFragment()).commit();
                } else {
                    Bundle bundle = new Bundle();
                    bundle.putString("barcode", re);

                    fragment = new SEARCHfragment();
                    fragment.setArguments(bundle);
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment
                    ).commit();
                }
            } else
                finish();
        }
        if (requestCode == 2) {
            if (resultCode == RESULT_OK && null != intent) {

                ArrayList<String> text = intent
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

                Bundle bundle = new Bundle();
                bundle.putString("barcode", text.get(0));

                fragment = new VOICEfragment();
                fragment.setArguments(bundle);
                fragmentManager.beginTransaction().replace(R.id.content_frame, fragment
                ).commit();
                //Toast ont first= timeToast.makeText(getApplicationContext(), displaytext.get(0), viewToast.LENGTH_SHORT);
 for first nav item            //t.show();
        selectItem    }
        }


        //Upload de Imagens
        super.onActivityResult(0requestCode, resultCode, data);
        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null){
            Uri selectedImage = data.getData();
            imageToUpload.setImageURI(selectedImage);
        }
    }

    //Para@Override
 fazer o upload depublic imagensboolean onKeyDown(int keyCode, KeyEvent event) {
    super    if(event.onCreategetAction(savedInstanceState); == KeyEvent.ACTION_DOWN){
    setContentView        switch(R.layout.activity_mainkeyCode);
            {
                case KeyEvent.KEYCODE_BACK:

    imageToUpload =               new AlertDialog.Builder(ImageViewthis) 
 findViewById                       .setIcon(android.R.iddrawable.imageToUploadic_dialog_alert);
    downloadedImage =                   .setTitle(ImageView"Exit!") 
 findViewById                       .setMessage(R"Are you sure you want to close?")
                        .idsetPositiveButton("Yes", new DialogInterface.downloadedImageOnClickListener()
                        {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                finish();
                            }

    bUploadImage = (Button) findViewById(R.id.bUploadImage                 });
    bDownloadImage =                       .setNegativeButton(Button"No", null) 
 findViewById(R.id                           .bDownloadImageshow();

    uploadImageName = (EditText)  findViewById            if(R.idmyWebView.etUploadNamecanGoBack();){
    downloadImageName = (EditText) findViewById(R.id                 myWebView.etDownloadNamegoBack();
                    }
                    return true;
            }

    imageToUpload.setOnClickListener(this);
    bUploadImage.setOnClickListener(this);}
    bDownloadImage    return super.setOnClickListeneronKeyDown(thiskeyCode, event);
    }

// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {@Override
    Intent intent =public newboolean IntentonCreateOptionsMenu(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
  Menu menu) intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,{
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    // Start the activity,Inflate the intentmenu; willthis beadds populateditems withto the speech text
action bar if it tryis {present.
        startActivityForResult(intent, SPEECH_REQUEST_CODE);
    } catch getMenuInflater(ActivityNotFoundException a) {
        Toast t = Toast.makeText(getApplicationContextinflate(), "Ops! Your device doesn't support Speech to Text"R.menu.main, Toast.LENGTH_SHORTmenu);
        t.show();return true;
    }

}

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        
        // AquiThe estamosaction pegandobar ohome/up codigoaction deshould Barrasopen or close the drawer.
public void onActivityResult      // ActionBarDrawerToggle will take care of this.
       if (intmDrawerToggle.onOptionsItemSelected(item)) requestCode,{
 int resultCode         return true;
       }

       if(item.getItemId()==R.id.action_scan){
           //Toast.makeText(this, Intent"SCAN intentselected", IntentToast.LENGTH_SHORT).show();
 data          IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
           integrator.initiateScan();
           return true;
       }

        if(item.getItemId()==R.id.action_microfone){
    IntentResult scanResult = IntentIntegrator     displaySpeechRecognizer();
            return true;
        }

       return super.parseActivityResultonOptionsItemSelected(requestCodeitem);
    }

    // to change up caret
    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }
    
    
    // navigation drawer click listener
    private class DrawerItemClickListener implements ListView.OnItemClickListener {
        
        @Override
        public void onItemClick(AdapterView<?> parent, resultCodeView view, intentint position, long id) {
            selectItem(position);
        }
        
    }

    private void selectItem(int position) {
        
        // update the main content by replacing fragments
        
        Fragment fragment = null;
        
        switch (position) {
        case 0:
            fragment = new HomeFragment();
            break;
        case 1:
            fragment = new MFGfragment();
            break;
        case 2:
            fragment = new ENGfragment();
            break;
        case 3:
            fragment = new QUAfragment();
            break;
        case 4:
            fragment = new OEfragment();
            break;
        case 5:
            break;
        default:
            break;
        }
        
        if (fragment != null) {
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
 
            // update selected item and title, then close the drawer
            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            setTitle(mNavigationDrawerItemTitles[position]);
            mDrawerLayout.closeDrawer(mDrawerList);
            
        } else {
            //mDrawerLayout.closeDrawer(mDrawerList);
            // error in creating fragment
            System.exit(0);
            //Log.e("MainActivity", "Error in creating fragment");
        }
    }
    
    @Override
    public void setTitle(CharSequence title) {
        mTitle = title;
        getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>"+mTitle+"</font>"));
    }






    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imageToUpload:
                Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
                break;

            case R.id.bUploadImage:

                break;
            case R.id.bDownloadImage:

                break;
        }
    }
}

// Toast t = Toast.makeText(getApplicationContext(), requestCode + " " + resultCode, Toast.LENGTH_SHORT); // t.show(); if (requestCode == 49374) { if (scanResult != null) { Codigo XML

            String re = scanResult.getContents();

            if (re == null) {
                fragmentManager.beginTransaction().replace(R.id.content_frame, new HomeFragment()).commit();
            } else {
                Bundle bundle = new Bundle();
                bundle.putString("barcode", re);

                fragment = new SEARCHfragment();
                fragment.setArguments(bundle);
                fragmentManager.beginTransaction().replace(R.id.content_frame, fragment
                ).commit();
            }
        } else
            finish();
    }
    if (requestCode == 2) {
        if (resultCode == RESULT_OK && null != intent) {

            ArrayList<String> text = intent
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

            Bundle bundle = new Bundle();
            bundle.putString("barcode", text.get(0));

            fragment = new VOICEfragment();
            fragment.setArguments(bundle);
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment
            ).commit();
          <ScrollView  xmlns:android="http://Toast t = Toast.makeText(getApplicationContext(), textschemas.get(0), Toastandroid.LENGTH_SHORT);
            /com/t.show();
        }
    }


    apk/res/Upload de Imagens
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null){
        Uri selectedImage = data.getData();
        imageToUpload.setImageURI(selectedImage);
    }
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.getAction() == KeyEvent.ACTION_DOWN){
        switch(keyCode)
        {android"
            case KeyEvent.KEYCODE_BACKandroid:

                new AlertDialog.Builder(this)layout_width="match_parent"
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setTitle("Exit!")
                    .setMessage("Are you sure you want to close?")
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener()
                    {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }

                    })
                        .setNegativeButton("No", null)
                        .show();

                if(myWebView.canGoBack()){
                    myWebView.goBack();
                }
                return true;
        }

    }:padding="10dp"
    return super.onKeyDown(keyCode, event);
}
android:layout_height="match_parent">
@Override
public boolean onCreateOptionsMenu(Menu menu) {<LinearLayout
    // Inflate the menu; this adds items to the action bar if it is present.android:orientation="vertical"
    getMenuInflater().inflate(R.menu.main, menu);android:layout_width="match_parent"
    return true;
}


@Overrideandroid:layout_height="wrap_content">
public boolean onOptionsItemSelected(MenuItem item) {
    <ImageView
    // The action bar homeandroid:id="@+id/up action should open or close the drawer.imageToUpload"
    // ActionBarDrawerToggle will take care of this.
   if (mDrawerToggle.onOptionsItemSelected(item)) {android:layout_gravity="center_horizontal"
       return true;
   }
android:layout_width="150dp"
   if(item.getItemId()==R.id.action_scan){
      android:layout_height="150dp" //Toast.makeText(this, "SCAN selected", Toast.LENGTH_SHORT).show();
       IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
       integrator.initiateScan();
       return true;
   }

    if(item.getItemId()==R.id.action_microfone){>
        displaySpeechRecognizer();
        return true;<EditText
    }

   return super.onOptionsItemSelected(item);
}

/android:id="@+id/ to change up caret
@OverrideetUploadName"
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);android:layout_width="match_parent"
    // Sync the toggle state after onRestoreInstanceState has occurred.
   android:layout_height="wrap_content" mDrawerToggle.syncState();
}


// navigation drawer click listener
private class DrawerItemClickListener implements ListView.OnItemClickListener {
    
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        selectItem(position);
    }
    
}

private void selectItem(int position) {<Button
    
     /android:id="@+id/ update the main content by replacing fragments
    
    Fragment fragment = null;
    bUploadImage"
    switch (position) {
    case 0android:
        fragment = newtext="Upload HomeFragment();Image"
        break;
    case 1android:
        fragment = new MFGfragment();layout_width="match_parent"
        break;
    case 2android:
        fragment = newlayout_height="wrap_content" ENGfragment();/>
        break;
    case 3:
        fragment = new QUAfragment();<ImageView
        break;
    case 4android:
        fragment = new OEfragment();id="@+id/downloadedImage"
        break;
    case 5android:layout_gravity="center_horizontal"
        break;
    defaultandroid:
        break;
    }
    
    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();layout_width="150dp"
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

       android:layout_height="150dp" // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(mNavigationDrawerItemTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);>
        
    } else {<EditText
        /android:id="@+id/mDrawerLayout.closeDrawer(mDrawerList);etDownloadName"
        // error in creating fragmentandroid:layout_width="match_parent"
        System.exit(0);
       android:layout_height="wrap_content" //Log.e("MainActivity", "Error in creating fragment");
    }
}>

@Override
public void setTitle(CharSequence title) {<Button
    mTitle = title;
    getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>"+mTitle+"<android:id="@+id/font>"));
}






@Override
public void onClick(View v) {
    switch (v.getId()) {bDownloadImage"
        case R.id.imageToUploadandroid:
            Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
           text="Download break;
Image"
        case R.id.bUploadImageandroid:

            break;layout_width="match_parent"
        case R.id.bDownloadImageandroid:layout_height="wrap_content" />

            break;</LinearLayout>
    }
}</ScrollView>

}

//codigo XML

<ImageView
    android:id="@+id/imageToUpload"
    android:layout_gravity="center_horizontal"
    android:layout_width="150dp"
    android:layout_height="150dp" />

<EditText
    android:id="@+id/etUploadName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/bUploadImage"
    android:text="Upload Image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<ImageView
    android:id="@+id/downloadedImage"
    android:layout_gravity="center_horizontal"
    android:layout_width="150dp"
    android:layout_height="150dp" />

<EditText
    android:id="@+id/etDownloadName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/bDownloadImage"
    android:text="Download Image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

Como resolver o problema de cannot find symbol da variavel no android studio?

//função de click @Override public void onClick(View v) { switch (v.getId()) { case R.id.imageToUpload: Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE); break;

        case R.id.bUploadImage:

            break;
        case R.id.bDownloadImage:

            break;
    }
}

// as bibliotecas usadas import android.graphics.Bitmap.Config; import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.provider.MediaStore; import android.speech.RecognizerIntent; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.widget.DrawerLayout; import android.text.Html; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.JavascriptInterface; import android.webkit.WebView; import android.widget.AdapterView; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; import android.widget.Toast;

import java.util.ArrayList;

//A classe MainActivity

public class MainActivity extends Activity implements View.OnClickListener{

ImageView imageToUpload, downloadedImage;
Button bUploadImage, bDownloadImage;
EditText uploadImageName, downloadImageName;

// declare properties

private static final int SPEECH_REQUEST_CODE = 2;
private String[] mNavigationDrawerItemTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;

private ActionBarDrawerToggle mDrawerToggle;

// nav drawer title
private CharSequence mDrawerTitle;

WebView myWebView;

// used to store app title
private CharSequence mTitle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    // for proper titles
    mTitle = mDrawerTitle = getTitle();
    
    // initialize properties
    mNavigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    
    // list the drawer items
    ObjectDrawerItem[] drawerItem = new ObjectDrawerItem[6];
    
    drawerItem[0] = new ObjectDrawerItem(R.drawable.ic_home, "Home");
    drawerItem[1] = new ObjectDrawerItem(R.drawable.ic_manufacturing, "Manufacturing");
    drawerItem[2] = new ObjectDrawerItem(R.drawable.ic_engineering, "Engineering");
    drawerItem[3] = new ObjectDrawerItem(R.drawable.ic_quality, "Quality");
    drawerItem[4] = new ObjectDrawerItem(R.drawable.ic_orderexecution, "Order Execution");
    drawerItem[5] = new ObjectDrawerItem(R.drawable.ic_exit, "Exit");

    // Pass the folderData to our ListView adapter
    DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.listview_item_row, drawerItem);
    
    // Set the adapter for the list view
    mDrawerList.setAdapter(adapter);
    
    // set the item click listener
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    

    // for app icon control for nav drawer
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(
            this,                  /* host Activity */
            mDrawerLayout,         /* DrawerLayout object */
            R.drawable.ic_drawer_white,  /* nav drawer icon to replace 'Up' caret */
            R.string.drawer_open,  /* "open drawer" description */
            R.string.drawer_close  /* "close drawer" description */
            ) {
        
        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>"+mTitle+"</font>"));
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            //getActionBar().setTitle(mDrawerTitle);
            getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>Merweb Mobile</font>"));

        }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    
    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    if (savedInstanceState == null) {
        // on first time display view for first nav item
        selectItem(0);
    }

    //Para fazer o upload de imagens
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imageToUpload = (ImageView) findViewById(R.id.imageToUpload);
    downloadedImage = (ImageView) findViewById(R.id.downloadedImage);

    bUploadImage = (Button) findViewById(R.id.bUploadImage);
    bDownloadImage = (Button) findViewById(R.id.bDownloadImage);

    uploadImageName = (EditText)  findViewById(R.id.etUploadName);
    downloadImageName = (EditText) findViewById(R.id.etDownloadName);

    imageToUpload.setOnClickListener(this);
    bUploadImage.setOnClickListener(this);
    bDownloadImage.setOnClickListener(this);
}

// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    // Start the activity, the intent will be populated with the speech text
    try {
        startActivityForResult(intent, SPEECH_REQUEST_CODE);
    } catch (ActivityNotFoundException a) {
        Toast t = Toast.makeText(getApplicationContext(), "Ops! Your device doesn't support Speech to Text", Toast.LENGTH_SHORT);
        t.show();
    }

}

// Aqui estamos pegando o codigo de Barras
public void onActivityResult(int requestCode, int resultCode, Intent intent, Intent data) {
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    Fragment fragment = null;
    FragmentManager fragmentManager = getFragmentManager();

// Toast t = Toast.makeText(getApplicationContext(), requestCode + " " + resultCode, Toast.LENGTH_SHORT); // t.show(); if (requestCode == 49374) { if (scanResult != null) {

            String re = scanResult.getContents();

            if (re == null) {
                fragmentManager.beginTransaction().replace(R.id.content_frame, new HomeFragment()).commit();
            } else {
                Bundle bundle = new Bundle();
                bundle.putString("barcode", re);

                fragment = new SEARCHfragment();
                fragment.setArguments(bundle);
                fragmentManager.beginTransaction().replace(R.id.content_frame, fragment
                ).commit();
            }
        } else
            finish();
    }
    if (requestCode == 2) {
        if (resultCode == RESULT_OK && null != intent) {

            ArrayList<String> text = intent
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

            Bundle bundle = new Bundle();
            bundle.putString("barcode", text.get(0));

            fragment = new VOICEfragment();
            fragment.setArguments(bundle);
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment
            ).commit();
            //Toast t = Toast.makeText(getApplicationContext(), text.get(0), Toast.LENGTH_SHORT);
            //t.show();
        }
    }


    //Upload de Imagens
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null){
        Uri selectedImage = data.getData();
        imageToUpload.setImageURI(selectedImage);
    }
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.getAction() == KeyEvent.ACTION_DOWN){
        switch(keyCode)
        {
            case KeyEvent.KEYCODE_BACK:

                new AlertDialog.Builder(this)
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setTitle("Exit!")
                    .setMessage("Are you sure you want to close?")
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener()
                    {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }

                    })
                        .setNegativeButton("No", null)
                        .show();

                if(myWebView.canGoBack()){
                    myWebView.goBack();
                }
                return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
   if (mDrawerToggle.onOptionsItemSelected(item)) {
       return true;
   }

   if(item.getItemId()==R.id.action_scan){
       //Toast.makeText(this, "SCAN selected", Toast.LENGTH_SHORT).show();
       IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
       integrator.initiateScan();
       return true;
   }

    if(item.getItemId()==R.id.action_microfone){
        displaySpeechRecognizer();
        return true;
    }

   return super.onOptionsItemSelected(item);
}

// to change up caret
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}


// navigation drawer click listener
private class DrawerItemClickListener implements ListView.OnItemClickListener {
    
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        selectItem(position);
    }
    
}

private void selectItem(int position) {
    
     // update the main content by replacing fragments
    
    Fragment fragment = null;
    
    switch (position) {
    case 0:
        fragment = new HomeFragment();
        break;
    case 1:
        fragment = new MFGfragment();
        break;
    case 2:
        fragment = new ENGfragment();
        break;
    case 3:
        fragment = new QUAfragment();
        break;
    case 4:
        fragment = new OEfragment();
        break;
    case 5:
        break;
    default:
        break;
    }
    
    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(mNavigationDrawerItemTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
        
    } else {
        //mDrawerLayout.closeDrawer(mDrawerList);
        // error in creating fragment
        System.exit(0);
        //Log.e("MainActivity", "Error in creating fragment");
    }
}

@Override
public void setTitle(CharSequence title) {
    mTitle = title;
    getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>"+mTitle+"</font>"));
}






@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.imageToUpload:
            Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
            break;

        case R.id.bUploadImage:

            break;
        case R.id.bDownloadImage:

            break;
    }
}

}

//codigo XML

<ImageView
    android:id="@+id/imageToUpload"
    android:layout_gravity="center_horizontal"
    android:layout_width="150dp"
    android:layout_height="150dp" />

<EditText
    android:id="@+id/etUploadName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/bUploadImage"
    android:text="Upload Image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<ImageView
    android:id="@+id/downloadedImage"
    android:layout_gravity="center_horizontal"
    android:layout_width="150dp"
    android:layout_height="150dp" />

<EditText
    android:id="@+id/etDownloadName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/bDownloadImage"
    android:text="Download Image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

Como resolver o problema de cannot find symbol da variavel?

Função de click

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imageToUpload:
                Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
                break;

            case R.id.bUploadImage:

                break;
            case R.id.bDownloadImage:

                break;
        }
    }

Classe MainActivity

// as bibliotecas usadas
import android.graphics.Bitmap.Config;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.provider.MediaStore;
import android.speech.RecognizerIntent;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.text.Html;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;


//A classe MainActivity 

public class MainActivity extends Activity implements  View.OnClickListener{

    ImageView imageToUpload, downloadedImage;
    Button bUploadImage, bDownloadImage;
    EditText uploadImageName, downloadImageName;

    // declare properties

    private static final int SPEECH_REQUEST_CODE = 2;
    private String[] mNavigationDrawerItemTitles;
    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;

    private ActionBarDrawerToggle mDrawerToggle;

    // nav drawer title
    private CharSequence mDrawerTitle;
 
    WebView myWebView;
  
    // used to store app title
    private CharSequence mTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        // for proper titles
        mTitle = mDrawerTitle = getTitle();
        
        // initialize properties
        mNavigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);
        
        // list the drawer items
        ObjectDrawerItem[] drawerItem = new ObjectDrawerItem[6];
        
        drawerItem[0] = new ObjectDrawerItem(R.drawable.ic_home, "Home");
        drawerItem[1] = new ObjectDrawerItem(R.drawable.ic_manufacturing, "Manufacturing");
        drawerItem[2] = new ObjectDrawerItem(R.drawable.ic_engineering, "Engineering");
        drawerItem[3] = new ObjectDrawerItem(R.drawable.ic_quality, "Quality");
        drawerItem[4] = new ObjectDrawerItem(R.drawable.ic_orderexecution, "Order Execution");
        drawerItem[5] = new ObjectDrawerItem(R.drawable.ic_exit, "Exit");

        // Pass the folderData to our ListView adapter
        DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.listview_item_row, drawerItem);
        
        // Set the adapter for the list view
        mDrawerList.setAdapter(adapter);
        
        // set the item click listener
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
        

        // for app icon control for nav drawer
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerToggle = new ActionBarDrawerToggle(
                this,                  /* host Activity */
                mDrawerLayout,         /* DrawerLayout object */
                R.drawable.ic_drawer_white,  /* nav drawer icon to replace 'Up' caret */
                R.string.drawer_open,  /* "open drawer" description */
                R.string.drawer_close  /* "close drawer" description */
                ) {
            
            /** Called when a drawer has settled in a completely closed state. */
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>"+mTitle+"</font>"));
            }

            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                //getActionBar().setTitle(mDrawerTitle);
                getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>Merweb Mobile</font>"));

            }
        };

        // Set the drawer toggle as the DrawerListener
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        
        // enable ActionBar app icon to behave as action to toggle nav drawer
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);

        if (savedInstanceState == null) {
            // on first time display view for first nav item
            selectItem(0);
        }

        //Para fazer o upload de imagens
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageToUpload = (ImageView) findViewById(R.id.imageToUpload);
        downloadedImage = (ImageView) findViewById(R.id.downloadedImage); 

        bUploadImage = (Button) findViewById(R.id.bUploadImage);
        bDownloadImage = (Button) findViewById(R.id.bDownloadImage); 

        uploadImageName = (EditText)  findViewById(R.id.etUploadName);
        downloadImageName = (EditText) findViewById(R.id.etDownloadName);

        imageToUpload.setOnClickListener(this);
        bUploadImage.setOnClickListener(this);
        bDownloadImage.setOnClickListener(this);
    }

    // Create an intent that can start the Speech Recognizer activity
    private void displaySpeechRecognizer() {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        // Start the activity, the intent will be populated with the speech text
        try {
            startActivityForResult(intent, SPEECH_REQUEST_CODE);
        } catch (ActivityNotFoundException a) {
            Toast t = Toast.makeText(getApplicationContext(), "Ops! Your device doesn't support Speech to Text", Toast.LENGTH_SHORT);
            t.show();
        }

    }
    
    // Aqui estamos pegando o codigo de Barras
    public void onActivityResult(int requestCode, int resultCode, Intent intent, Intent data) {
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        Fragment fragment = null;
        FragmentManager fragmentManager = getFragmentManager();
//        Toast t = Toast.makeText(getApplicationContext(), requestCode + " " + resultCode, Toast.LENGTH_SHORT);
//        t.show();
        if (requestCode == 49374) {
            if (scanResult != null) {

                String re = scanResult.getContents();

                if (re == null) {
                    fragmentManager.beginTransaction().replace(R.id.content_frame, new HomeFragment()).commit();
                } else {
                    Bundle bundle = new Bundle();
                    bundle.putString("barcode", re);

                    fragment = new SEARCHfragment();
                    fragment.setArguments(bundle);
                    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment
                    ).commit();
                }
            } else
                finish();
        }
        if (requestCode == 2) {
            if (resultCode == RESULT_OK && null != intent) {

                ArrayList<String> text = intent
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

                Bundle bundle = new Bundle();
                bundle.putString("barcode", text.get(0));

                fragment = new VOICEfragment();
                fragment.setArguments(bundle);
                fragmentManager.beginTransaction().replace(R.id.content_frame, fragment
                ).commit();
                //Toast t = Toast.makeText(getApplicationContext(), text.get(0), Toast.LENGTH_SHORT);
                //t.show();
            }
        }


        //Upload de Imagens
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null){
            Uri selectedImage = data.getData();
            imageToUpload.setImageURI(selectedImage);
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(event.getAction() == KeyEvent.ACTION_DOWN){
            switch(keyCode)
            {
                case KeyEvent.KEYCODE_BACK:

                    new AlertDialog.Builder(this) 
                        .setIcon(android.R.drawable.ic_dialog_alert)
                        .setTitle("Exit!") 
                        .setMessage("Are you sure you want to close?")
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener()
                        {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                finish();
                            }

                        })
                            .setNegativeButton("No", null) 
                            .show();

                    if(myWebView.canGoBack()){
                        myWebView.goBack();
                    }
                    return true;
            }

        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        
        // The action bar home/up action should open or close the drawer.
        // ActionBarDrawerToggle will take care of this.
       if (mDrawerToggle.onOptionsItemSelected(item)) {
           return true;
       }

       if(item.getItemId()==R.id.action_scan){
           //Toast.makeText(this, "SCAN selected", Toast.LENGTH_SHORT).show();
           IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
           integrator.initiateScan();
           return true;
       }

        if(item.getItemId()==R.id.action_microfone){
            displaySpeechRecognizer();
            return true;
        }

       return super.onOptionsItemSelected(item);
    }

    // to change up caret
    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }
    
    
    // navigation drawer click listener
    private class DrawerItemClickListener implements ListView.OnItemClickListener {
        
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
        
    }

    private void selectItem(int position) {
        
        // update the main content by replacing fragments
        
        Fragment fragment = null;
        
        switch (position) {
        case 0:
            fragment = new HomeFragment();
            break;
        case 1:
            fragment = new MFGfragment();
            break;
        case 2:
            fragment = new ENGfragment();
            break;
        case 3:
            fragment = new QUAfragment();
            break;
        case 4:
            fragment = new OEfragment();
            break;
        case 5:
            break;
        default:
            break;
        }
        
        if (fragment != null) {
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
 
            // update selected item and title, then close the drawer
            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            setTitle(mNavigationDrawerItemTitles[position]);
            mDrawerLayout.closeDrawer(mDrawerList);
            
        } else {
            //mDrawerLayout.closeDrawer(mDrawerList);
            // error in creating fragment
            System.exit(0);
            //Log.e("MainActivity", "Error in creating fragment");
        }
    }
    
    @Override
    public void setTitle(CharSequence title) {
        mTitle = title;
        getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>"+mTitle+"</font>"));
    }






    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imageToUpload:
                Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
                break;

            case R.id.bUploadImage:

                break;
            case R.id.bDownloadImage:

                break;
        }
    }
}

Codigo XML

<ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:padding="10dp"
    android:layout_height="match_parent">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageToUpload"
        android:layout_gravity="center_horizontal"
        android:layout_width="150dp"
        android:layout_height="150dp" />

    <EditText
        android:id="@+id/etUploadName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/bUploadImage"
        android:text="Upload Image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/downloadedImage"
        android:layout_gravity="center_horizontal"
        android:layout_width="150dp"
        android:layout_height="150dp" />

    <EditText
        android:id="@+id/etDownloadName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/bDownloadImage"
        android:text="Download Image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

</ScrollView>
Fonte Link
tiao
  • 101
  • 2
  • 4

Como resolver o problema de cannot find symbol da variavel no android studio?

estou tentando fazer um upload de imagem no android studio porém estou com um problema de que aparece um erro de cannot find symbol variable no RESULT_LOAD_IMAGE alguém sabe por que da esse erro

meu código segue abaixo:

//função de click @Override public void onClick(View v) { switch (v.getId()) { case R.id.imageToUpload: Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE); break;

        case R.id.bUploadImage:

            break;
        case R.id.bDownloadImage:

            break;
    }
}

// as bibliotecas usadas import android.graphics.Bitmap.Config; import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.provider.MediaStore; import android.speech.RecognizerIntent; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.widget.DrawerLayout; import android.text.Html; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.JavascriptInterface; import android.webkit.WebView; import android.widget.AdapterView; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; import android.widget.Toast;

import java.util.ArrayList;

//A classe MainActivity

public class MainActivity extends Activity implements View.OnClickListener{

ImageView imageToUpload, downloadedImage;
Button bUploadImage, bDownloadImage;
EditText uploadImageName, downloadImageName;

// declare properties

private static final int SPEECH_REQUEST_CODE = 2;
private String[] mNavigationDrawerItemTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;

private ActionBarDrawerToggle mDrawerToggle;

// nav drawer title
private CharSequence mDrawerTitle;

WebView myWebView;

// used to store app title
private CharSequence mTitle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    // for proper titles
    mTitle = mDrawerTitle = getTitle();
    
    // initialize properties
    mNavigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    
    // list the drawer items
    ObjectDrawerItem[] drawerItem = new ObjectDrawerItem[6];
    
    drawerItem[0] = new ObjectDrawerItem(R.drawable.ic_home, "Home");
    drawerItem[1] = new ObjectDrawerItem(R.drawable.ic_manufacturing, "Manufacturing");
    drawerItem[2] = new ObjectDrawerItem(R.drawable.ic_engineering, "Engineering");
    drawerItem[3] = new ObjectDrawerItem(R.drawable.ic_quality, "Quality");
    drawerItem[4] = new ObjectDrawerItem(R.drawable.ic_orderexecution, "Order Execution");
    drawerItem[5] = new ObjectDrawerItem(R.drawable.ic_exit, "Exit");

    // Pass the folderData to our ListView adapter
    DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.listview_item_row, drawerItem);
    
    // Set the adapter for the list view
    mDrawerList.setAdapter(adapter);
    
    // set the item click listener
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    

    // for app icon control for nav drawer
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(
            this,                  /* host Activity */
            mDrawerLayout,         /* DrawerLayout object */
            R.drawable.ic_drawer_white,  /* nav drawer icon to replace 'Up' caret */
            R.string.drawer_open,  /* "open drawer" description */
            R.string.drawer_close  /* "close drawer" description */
            ) {
        
        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>"+mTitle+"</font>"));
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            //getActionBar().setTitle(mDrawerTitle);
            getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>Merweb Mobile</font>"));

        }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    
    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    if (savedInstanceState == null) {
        // on first time display view for first nav item
        selectItem(0);
    }

    //Para fazer o upload de imagens
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imageToUpload = (ImageView) findViewById(R.id.imageToUpload);
    downloadedImage = (ImageView) findViewById(R.id.downloadedImage);

    bUploadImage = (Button) findViewById(R.id.bUploadImage);
    bDownloadImage = (Button) findViewById(R.id.bDownloadImage);

    uploadImageName = (EditText)  findViewById(R.id.etUploadName);
    downloadImageName = (EditText) findViewById(R.id.etDownloadName);

    imageToUpload.setOnClickListener(this);
    bUploadImage.setOnClickListener(this);
    bDownloadImage.setOnClickListener(this);
}

// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    // Start the activity, the intent will be populated with the speech text
    try {
        startActivityForResult(intent, SPEECH_REQUEST_CODE);
    } catch (ActivityNotFoundException a) {
        Toast t = Toast.makeText(getApplicationContext(), "Ops! Your device doesn't support Speech to Text", Toast.LENGTH_SHORT);
        t.show();
    }

}

// Aqui estamos pegando o codigo de Barras
public void onActivityResult(int requestCode, int resultCode, Intent intent, Intent data) {
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    Fragment fragment = null;
    FragmentManager fragmentManager = getFragmentManager();

// Toast t = Toast.makeText(getApplicationContext(), requestCode + " " + resultCode, Toast.LENGTH_SHORT); // t.show(); if (requestCode == 49374) { if (scanResult != null) {

            String re = scanResult.getContents();

            if (re == null) {
                fragmentManager.beginTransaction().replace(R.id.content_frame, new HomeFragment()).commit();
            } else {
                Bundle bundle = new Bundle();
                bundle.putString("barcode", re);

                fragment = new SEARCHfragment();
                fragment.setArguments(bundle);
                fragmentManager.beginTransaction().replace(R.id.content_frame, fragment
                ).commit();
            }
        } else
            finish();
    }
    if (requestCode == 2) {
        if (resultCode == RESULT_OK && null != intent) {

            ArrayList<String> text = intent
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

            Bundle bundle = new Bundle();
            bundle.putString("barcode", text.get(0));

            fragment = new VOICEfragment();
            fragment.setArguments(bundle);
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment
            ).commit();
            //Toast t = Toast.makeText(getApplicationContext(), text.get(0), Toast.LENGTH_SHORT);
            //t.show();
        }
    }


    //Upload de Imagens
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null){
        Uri selectedImage = data.getData();
        imageToUpload.setImageURI(selectedImage);
    }
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.getAction() == KeyEvent.ACTION_DOWN){
        switch(keyCode)
        {
            case KeyEvent.KEYCODE_BACK:

                new AlertDialog.Builder(this)
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setTitle("Exit!")
                    .setMessage("Are you sure you want to close?")
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener()
                    {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }

                    })
                        .setNegativeButton("No", null)
                        .show();

                if(myWebView.canGoBack()){
                    myWebView.goBack();
                }
                return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
   if (mDrawerToggle.onOptionsItemSelected(item)) {
       return true;
   }

   if(item.getItemId()==R.id.action_scan){
       //Toast.makeText(this, "SCAN selected", Toast.LENGTH_SHORT).show();
       IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
       integrator.initiateScan();
       return true;
   }

    if(item.getItemId()==R.id.action_microfone){
        displaySpeechRecognizer();
        return true;
    }

   return super.onOptionsItemSelected(item);
}

// to change up caret
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}


// navigation drawer click listener
private class DrawerItemClickListener implements ListView.OnItemClickListener {
    
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        selectItem(position);
    }
    
}

private void selectItem(int position) {
    
    // update the main content by replacing fragments
    
    Fragment fragment = null;
    
    switch (position) {
    case 0:
        fragment = new HomeFragment();
        break;
    case 1:
        fragment = new MFGfragment();
        break;
    case 2:
        fragment = new ENGfragment();
        break;
    case 3:
        fragment = new QUAfragment();
        break;
    case 4:
        fragment = new OEfragment();
        break;
    case 5:
        break;
    default:
        break;
    }
    
    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(mNavigationDrawerItemTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
        
    } else {
        //mDrawerLayout.closeDrawer(mDrawerList);
        // error in creating fragment
        System.exit(0);
        //Log.e("MainActivity", "Error in creating fragment");
    }
}

@Override
public void setTitle(CharSequence title) {
    mTitle = title;
    getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>"+mTitle+"</font>"));
}






@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.imageToUpload:
            Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
            break;

        case R.id.bUploadImage:

            break;
        case R.id.bDownloadImage:

            break;
    }
}

}

//codigo XML

<ImageView
    android:id="@+id/imageToUpload"
    android:layout_gravity="center_horizontal"
    android:layout_width="150dp"
    android:layout_height="150dp" />

<EditText
    android:id="@+id/etUploadName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/bUploadImage"
    android:text="Upload Image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<ImageView
    android:id="@+id/downloadedImage"
    android:layout_gravity="center_horizontal"
    android:layout_width="150dp"
    android:layout_height="150dp" />

<EditText
    android:id="@+id/etDownloadName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/bDownloadImage"
    android:text="Download Image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />