Results 1 to 4 of 4
- 11-04-2012, 07:25 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 2
- Rep Power
- 0
Android development, Syntax Errors, and "}" driving me insane
Hello,
I am working on creating a soundboard. This isn't my first time building one, but I have only used templates, and the template I had when I made my first soundboard didn't have the code in it to allow the user to long press save a tone, which is a feature I want. I found a template that does, but the template itself is full of errors before I do anything with it, plus it's got the Google AdMob built in already, which isn't something I want right now. So I decided that I would frankenstein the 2 codes together. I started with a small section, just the long press save code beginning area and the first button. I was able to get it all to match and all of the errors to go away.
Except 1. And it is going to drive me mad if I don't fix it.
Here you go:
The first error is at the "}" here and reads "Syntax error, insert "}" to complete ClassBody":Java Code:package com.soundboard; import com.soundboard.SoundManager; import android.app.Activity; import android.os.Bundle; import android.view.ContextMenu; import android.view.MenuItem; import android.view.View; import android.view.ContextMenu.ContextMenuInfo; import android.view.View.OnClickListener; import android.widget.Button; public class Soundboard extends Activity { private SoundManager mSoundManager; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mSoundManager = new SoundManager(); mSoundManager.initSounds(getBaseContext()); mSoundManager.addSound(1, R.raw.sound1); mSoundManager.addSound(2, R.raw.sound2); mSoundManager.addSound(3, R.raw.sound3); mSoundManager.addSound(4, R.raw.sound4); mSoundManager.addSound(5, R.raw.sound5); mSoundManager.addSound(6, R.raw.sound6); mSoundManager.addSound(7, R.raw.sound7); mSoundManager.addSound(8, R.raw.sound8); mSoundManager.addSound(9, R.raw.sound9); mSoundManager.addSound(10, R.raw.sound10); mSoundManager.addSound(11, R.raw.sound11); mSoundManager.addSound(12, R.raw.sound12); mSoundManager.addSound(13, R.raw.sound13); mSoundManager.addSound(14, R.raw.sound14); mSoundManager.addSound(15, R.raw.sound15); mSoundManager.addSound(16, R.raw.sound16); mSoundManager.addSound(17, R.raw.sound17); mSoundManager.addSound(18, R.raw.sound18); mSoundManager.addSound(19, R.raw.sound19); mSoundManager.addSound(20, R.raw.sound20); mSoundManager.addSound(21, R.raw.sound21); mSoundManager.addSound(22, R.raw.sound22); mSoundManager.addSound(23, R.raw.sound23); mSoundManager.addSound(24, R.raw.sound24); mSoundManager.addSound(25, R.raw.sound25); mSoundManager.addSound(26, R.raw.sound26); mSoundManager.addSound(27, R.raw.sound27); mSoundManager.addSound(28, R.raw.sound28); mSoundManager.addSound(29, R.raw.sound29); mSoundManager.addSound(30, R.raw.sound30); Button SoundButton1 = (Button)findViewById(R.id.sound1); SoundButton1.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(1); } }); Button SoundButton2 = (Button)findViewById(R.id.sound2); SoundButton2.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(2); } }); Button SoundButton3 = (Button)findViewById(R.id.sound3); SoundButton3.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(3); } }); Button SoundButton4 = (Button)findViewById(R.id.sound4); SoundButton4.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(4); } }); Button SoundButton5 = (Button)findViewById(R.id.sound5); SoundButton5.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(5); } }); Button SoundButton6 = (Button)findViewById(R.id.sound6); SoundButton6.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(6); } }); Button SoundButton7 = (Button)findViewById(R.id.sound7); SoundButton7.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(7); } }); Button SoundButton8 = (Button)findViewById(R.id.sound8); SoundButton8.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(8); } }); Button SoundButton9 = (Button)findViewById(R.id.sound9); SoundButton9.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(9); } }); Button SoundButton10 = (Button)findViewById(R.id.sound10); SoundButton10.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(10); } }); Button SoundButton11 = (Button)findViewById(R.id.sound11); SoundButton11.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(11); } }); Button SoundButton12 = (Button)findViewById(R.id.sound12); SoundButton12.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(12); } }); Button SoundButton13 = (Button)findViewById(R.id.sound13); SoundButton13.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(13); } }); Button SoundButton14 = (Button)findViewById(R.id.sound14); SoundButton14.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(14); } }); Button SoundButton15 = (Button)findViewById(R.id.sound15); SoundButton15.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(15); } }); Button SoundButton16 = (Button)findViewById(R.id.sound16); SoundButton16.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(16); } }); Button SoundButton17 = (Button)findViewById(R.id.sound17); SoundButton17.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(17); } }); Button SoundButton18 = (Button)findViewById(R.id.sound18); SoundButton18.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(18); } }); Button SoundButton19 = (Button)findViewById(R.id.sound19); SoundButton19.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(19); } }); Button SoundButton20 = (Button)findViewById(R.id.sound20); SoundButton20.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(20); } }); Button SoundButton21 = (Button)findViewById(R.id.sound21); SoundButton21.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(21); } }); Button SoundButton22 = (Button)findViewById(R.id.sound22); SoundButton22.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(22); } }); Button SoundButton23 = (Button)findViewById(R.id.sound23); SoundButton23.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(23); } }); Button SoundButton24 = (Button)findViewById(R.id.sound24); SoundButton24.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(24); } }); Button SoundButton25 = (Button)findViewById(R.id.sound25); SoundButton25.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(25); } }); Button SoundButton26 = (Button)findViewById(R.id.sound26); SoundButton26.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(26); } }); Button SoundButton27 = (Button)findViewById(R.id.sound27); SoundButton27.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(27); } }); Button SoundButton28 = (Button)findViewById(R.id.sound28); SoundButton28.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(28); } }); Button SoundButton29 = (Button)findViewById(R.id.sound29); SoundButton29.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(29); } }); Button SoundButton30 = (Button)findViewById(R.id.sound30); SoundButton30.setOnClickListener(new OnClickListener() { public void onClick(View v) { mSoundManager.playSound(30); } }); } // perform save functions on long press public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.setHeaderTitle("Save as..."); menu.add(0, v.getId(), 0, "Ringtone/Notification"); } { } @Override public boolean onContextItemSelected(MenuItem item) { if(item.getTitle()=="Ringtone/Notification"){function1(item.getItemId());} else {return false;} return true; } // detect which button was clicked, save as a ringtone with strings.xml public boolean function1(int ressound){ //---- String soundname = ""; switch(ressound){ case R.id.sound1: ressound = R.raw.sound1; soundname = (this.getString(R.string.app_name)) + " - " + (this.getString(R.string.quote01)); break; }
Java Code:@Override public boolean onContextItemSelected(MenuItem item) { if(item.getTitle()=="Ringtone/Notification"){function1(item.getItemId());} else {return false;} return true; }
The second error is at "}" here and reads "Syntax error, insert "}" to complete MethodBody":
So with both of these I try to do the logical thing and add "}" like it asks for. But for some crazy reason, when I do add "}" then I get 2 errors:Java Code://---- String soundname = ""; switch(ressound){ case R.id.sound1: ressound = R.raw.sound1; soundname = (this.getString(R.string.app_name)) + " - " + (this.getString(R.string.quote01)); break; }
Syntax error, insert "}" to complete ClassBody (or later MethodBody)
Syntax error on token "}", delete this token
I am at a loss as to what to do at this point. I have been fighting with it for 3 days now. Is there anyone who can help me out here?Last edited by LadyRaevyn; 11-04-2012 at 09:05 PM.
-
Re: Android development, Syntax Errors, and "}" driving me insane
Somehow your opening and closing braces are not matching up, and usually this is easily detected when the code is well formatted with consistent and well placed indentations, consistent and well placed use of white space, in other words with well formatted code.
Your code as posted is very hard to read given that we can't see the formatting and you are not using white space enough. Consider editing your post above and wrap your code in [code] [/code] tags so that it retains its formatting. Also you will want to use white space to your advantage by placing every Java statement on its own line. There's no penalty in doing this and it greatly increases the readability of your code. since you're asking strangers who are volunteers to read and understand your code and then help you, doing this greatly increase your chances of getting good help. Also consider posting the entire class if not too large.
- 11-04-2012, 09:07 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 2
- Rep Power
- 0
-
Re: Android development, Syntax Errors, and "}" driving me insane
Your indentations are quite a bit messed up, are all over the map in fact. consider using 3 spaces and 3 spaces only for each indentation, and making the uniform. If you're coding in Eclipse, it can help do this for you by going into the Window - Preferences menu and setting the Java - Code Style - Formatter to the appropriate settings including a tab policy of spaces only an indentation and tab size of 3. Then you can highlight your entire code and press alt-s f (for source, format).
Also it looks like you've been adding code to non-compilable code, something you should never do. If not using an IDE, compile often and correct compilation errors before adding new code. Note that if your code were clean and well formatted to start with, you wouldn't likely be having this error. So from now forward, strive for creating clean code only.
Similar Threads
-
Cannot find symbol: This is driving me insane!
By ayershov777 in forum New To JavaReplies: 6Last Post: 09-29-2012, 11:39 AM -
Syntax error on token "}", super expected
By amentjacob1 in forum New To JavaReplies: 9Last Post: 07-06-2012, 04:15 AM -
Iteration - "dangling modifier", wrong syntax
By Tom_Snake in forum New To JavaReplies: 4Last Post: 10-14-2011, 12:08 AM -
jsp "Valu incrementing Syntax""
By nHulk in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 04-27-2011, 11:52 AM -
Driving me insane - Program not working as it should ><
By mainy in forum New To JavaReplies: 1Last Post: 08-27-2009, 01:20 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks